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

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -