node.js - Remove some properties from array of javascript objects -


i remove properties array of javascript objects. here array of objects.

obj_array = [{         "data_id": 1,         "data_name": "jim",         "data_bb_typ": 2,         "data_mac": "5474",     },     {         "data_id": 3,         "data_name": "fro",         "data_bb_typ": 33,         "data_mac": "8e30",     },     {         "data_id": 2,         "data_name": "jimb",         "data_bb_typ": 2,         "data_mac": "45e8",     },     {         "data_id": 4,         "data_name": "kht1",         "data_bb_typ": 35,         "data_mac": "58d0",     },     {         "data_id": 6,         "data_name": "sens",         "data_bb_typ": 34,         "data_mac": "d004",     } ] 

i have string array specifies properties remove.

var str_array_criteria = ["data_bb_typ", "data_mac"]; 

after removal, array of object this;

obj_array_removed = [{         "data_id": 1,         "data_name": "jim",             },     {         "data_id": 3,         "data_name": "fro",     },     {         "data_id": 2,         "data_name": "jimb",     },     {         "data_id": 4,         "data_name": "kht1",     },     {         "data_id": 6,         "data_name": "sens",     } ] 

i using node.js v6.

here go,

var obj_array = [{          "data_id": 1,          "data_name": "jim",          "data_bb_typ": 2,          "data_mac": "5474",      },      {          "data_id": 3,          "data_name": "fro",          "data_bb_typ": 33,          "data_mac": "8e30",      },      {          "data_id": 2,          "data_name": "jimb",          "data_bb_typ": 2,          "data_mac": "45e8",      },      {          "data_id": 4,          "data_name": "kht1",          "data_bb_typ": 35,          "data_mac": "58d0",      },      {          "data_id": 6,          "data_name": "sens",          "data_bb_typ": 34,          "data_mac": "d004",      }  ];        var str_array_criteria = ["data_bb_typ", "data_mac"];        var new_obj_array = obj_array.map(function(obj) {        str_array_criteria.foreach(function(prop) {          delete obj[prop];        });                return obj;      });        console.log(new_obj_array);


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -