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..

http://jsfiddle.net/spechackers/43htd/


Comments

Popular posts from this blog

javascript - Iterate over array and calculate average values of array-parts -

iphone - Using nested NSDictionary with Picker -

objective c - Newbie question -multiple parameters -