Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

find all empty values in JSON object using javascript

I want to print all empty values in JSON. if all values are not empty then it should print JSON has no empty fields.

  

  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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

We can combine Object.keys() and Array.filter() to do it

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading