javascript - Remove false values in object -
the problem i'm facing -removing values in onject has property false
here object
var myobj={105:true,183:false,108:true,106:false}
i'm able values in array using following logic:
object.keys(myobj)
gives ["105","183","108","106"]
need way remove values have property false , generate ["105",108"]
.can me out ?
i've created solution problem on jsbin: working demo
please find below code:
var myobj={105:true,183:false,108:true,106:false}; var myarray = []; function removefalseandtransformtoarray () { (var key in myobj) { if(myobj[key] === false) { delete myobj[key]; } else { myarray.push(key); } } } removefalseandtransformtoarray(); console.log("myobj: ", myobj); console.log("myarray: ", myarray); // result = ["105", "108"]
please, let me know if have question.
Comments
Post a Comment