使用javascript [duplicate]查找JSON对象中的所有空值

k10s72fa  于 2022-11-19  发布在  Java
关注(0)|答案(1)|浏览(135)

此问题在此处已有答案

Return an object key only if value is true(5个答案)
Get all keys from object that have a specific value [duplicate](1个答案)
18小时前关门了。
我想打印JSON中的所有空值。如果所有值都不是空的,那么它应该打印JSON没有空字段。

let obj = {
  "name" : "abc",
  "sub_name" : "some name",
  "language" : "",
  "skills" : "",
  "device" : "device_name",
  "color" : "",
  
} 


I want to have all the empty keys in JSON

output : 

[language, skills, colour] have empty values
rdlzhqv9

rdlzhqv91#

我们可以合并Object.keys()Array.filter()来实现

let obj = {
  "name" : "abc",
  "sub_name" : "some name",
  "language" : "",
  "skills" : "",
  "device" : "device_name",
  "color" : "",
  
} 

let result = Object.keys(obj).filter(b => !obj[b])
console.log(result)

相关问题