javascript - Removing unwanted keys from my array of objects -
my object
how remove keys userid, username it... mean selected keys... delete operator not working in case.
for (i=0 <obj.length; ++) { delete obj[i]['keyname']; }
the above not work, neither throws error. other way...
how solution....
array.prototype.containsvalue = function (value) { (var k in this) { if (!this.hasownproperty(k)) { continue; } //skip inherited properties if (this[k] == value) { return true; } } return false; }; (var key in object) { var unwantedkeys = ['username', 'userid']; if (unwantedkeys.containsvalue(key)) continue; // play object won't contain these unwanted keys. }
delete should work, not sure mistake doing..
Comments
Post a Comment