如何从下面的输入中删除包含空值的属性
var data = [
{ "Id": "parent", "Function": "Project Management", "Phase": "(Null)" },
{ "Id": "1", "Function": "R&D Team", "Phase": "parent" },
{ "Id": "2", "Function": "HR Team", "Phase": "parent" },
{ "Id": "3", "Function": "Sales Team", "Phase": "parent" },
{ "Id": "4", "Function": "Philosophy", "Phase": "1" },
{ "Id": "5", "Function": " Organization", "Phase": "1" },
];
最佳答案
您可以这样做:
data = data.map(obj => Object.keys(obj).reduce((prev, prop) => {
// you can check for '(Null)', null or for any different kind of value here
if (obj[prop] != '(Null)') {
prev[prop] = obj[prop]
}
return prev
}, {}))
关于javascript - 如何从json输入中删除null值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48108088/