Remove Object from Array using JavaScript

前端 未结 29 2579
南笙
南笙 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:50

    Here is an example with map and splice

    const arrayObject = [
      { name: "name1", value: "value1" },
      { name: "name2", value: "value2" },
      { name: "name3", value: "value3" },
    ];
    
    let index = arrayObject.map((item) => item.name).indexOf("name1");
    if (index > -1) {
      
      arrayObject.splice(index, 1);
      console.log("Result", arrayObject);
      
    
    }

提交回复
热议问题