字符串中的javascript null值 [英] javascript null value in string

查看:73
本文介绍了字符串中的javascript null值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在javascript中我有以下内容:

In javascript I have the following:

var inf = id + '|' + city ;

如果id或city为null,则inf为null。

if id or city are null then inf will be null.

如果id或city为null,是否有任何光滑的方式说空白。

Is there any slick way of saying if id or city are null make then blank.

我知道在c#中你可以做以下事情:

I know in c# you can do the following:

var inf = (id ?? "") + (city ?? "");

javascript中的任何类似方法?

Any similar method in javascript?

推荐答案

var inf = (id == null ? '' : id) + '|' + (city == null ? '' : city)

这篇关于字符串中的javascript null值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆