+ 1

How can I output the object and its balue which its value > 0?

How can I output the object and its value which its value > 0? Please check this: https://paste.lucko.me/sYtNNne2yS What should BLAH1, BLAH2, BLAH3 and BLAH4 be?

9th Jul 2019, 11:51 AM
デジモン Lover
デジモン Lover - avatar
2 Answers
+ 4
const json = `{ "N0909": { "Starter Package": 12, "Stone": 2942, "Spruce Log": 0, "Oak Log": 932, "Iron": 0 } }`; var obj = JSON.parse(json).N0909; // get the object var output = []; for(var key in obj) { if(obj[key]>0) output.push(key) } console.log(output.join(',')) // output is keys with value>0 (in array) https://code.sololearn.com/WQ8bj5kmYRKl/?ref=app
9th Jul 2019, 12:20 PM
CalviŐ˛
CalviŐ˛ - avatar
+ 2
oh thx!
9th Jul 2019, 12:22 PM
デジモン Lover
デジモン Lover - avatar