+ 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?
2 Respuestas
+ 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
+ 2
oh thx!