Remove Object from Array using JavaScript

前端 未结 29 2881
南笙
南笙 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条回答
  •  我在风中等你
    2020-11-22 10:49

    You can use map function also.

    someArray = [{name:"Kristian", lines:"2,5,10"},{name:"John",lines:"1,19,26,96"}];
    newArray=[];
    someArray.map(function(obj, index){
        if(obj.name !== "Kristian"){
           newArray.push(obj);
        }
    });
    someArray = newArray;
    console.log(someArray);
    

提交回复
热议问题