我的代码如下所示:
var data = someDataWhichComesFromOtherMethod
var array = [
{name: "one", value:"data1", caption:"aaa"...},
{name: "two", value:"data2", caption:"bbb"...},
{name: "three", value:"data3", caption:"ccc"...},
{name: "four", value:"data4", caption:"ddd"...}
...
]
我想要做的是:首先检查array
是否为空,然后检查传入data
是否为真,如果不是,则需要从中删除整个对象阵列。
我开始时:
if (array && array.length) {
//true
} else {
//false
}
例如,如果data4
为null
或""
,则array
应如下所示:
var array = [
{name: "one", value:"data1", caption:"aaa"...},
{name: "two", value:"data2", caption:"bbb"...},
{name: "three", value:"data3", caption:"ccc"...}
...
]