js 过滤数组中的空值或null
1. let
data = {
"terminalCode"
:
"T0014077"
,
"terminalName"
:
"测试门店4"
,
"licenseName"
:
"山西太原XXX超市"
,
"terminalAddress"
:
"山西太原杏花岭"
,
"shopkeeperName"
:
"马宇"
,
"shopkeeperPhone"
:
"13766662222"
,
"licenseCode"
:
"ADEAF546656"
,
"licenseAddress"
:
null
,
"channelType"
:
"01"
,
"marketTypeCode"
:
"S001"
,
"endTime"
:
"2019-11-30"
}
let
arr = {}
for
(
let
key
in
data){
arr[key] = data[key]?data[key]:
''
}
console.log(arr)
2. js 数组过滤空值(undefined、null、""、0、false、NaN)
const arr = [undefined, null, "", 0, false, NaN, 1, 2].filter(Boolean);