简体   繁体   中英

remove an object from an object array in javascript

I have an object which is like:

Object {w74: Object, w100: Object,w12: Object,w3: Object}

I need to eleminate one of them to have

Object {w74: Object, w100: Object,w3: Object}

How can remove this in javascript

Use the delete operator :

 var ob = {w74: {number: 1}, w100: {number: 2},w12: {number: 3},w3: {number: 4}}; console.log(ob); delete ob.w74; console.log(ob); 

You can directly delete your value from object by key value

eg.

 var arrChildOptions2 = {
       w74: Object, w100: Object,w12: Object,w3: Object
     };

delete arrChildOptions2.w12;

Use underscore library function called _.pick() http://underscorejs.org/#pick

_.pick({name: 'moe', age: 50, userid: 'moe1'}, 'name', 'age');
=> {name: 'moe', age: 50}

_.pick({name: 'moe', age: 50, userid: 'moe1'}, function(value, key, object) {
  return _.isNumber(value);
});
=> {age: 50}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM