function to remove object properties from an array of objects - Javascript Array Operation

Javascript examples for Array Operation:Array of Object

Description

function to remove object properties from an array of objects

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from  w  w w  .j  av  a  2 s  . c  o m*/
var my = function (listObj,key) {
    for (var i = 0;i < listObj.length; i++) {
        for(var k in listObj[i])
        if (k!=key) {
            delete listObj[i][k];
        }
    }
    return listObj;
}
console.log(JSON.stringify(my([{a: 'b', c:'d'}, {a: 'q'}], 'a')));
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials