Remove Object from Array using JavaScript

前端 未结 29 2597
南笙
南笙 2020-11-22 10:24

How can I remove an object from an array? I wish to remove the object that includes name Kristian from someArray. For example:

som         


        
29条回答
  •  萌比男神i
    2020-11-22 10:57

    I recommend using lodash.js or sugar.js for common tasks like this:

    // lodash.js
    someArray = _.reject(someArray, function(el) { return el.Name === "Kristian"; });
    
    // sugar.js
    someArray.remove(function(el) { return el.Name === "Kristian"; });
    

    in most projects, having a set of helper methods that is provided by libraries like these is quite useful.

提交回复
热议问题