Remove Object from Array using JavaScript

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

    Although this is probably not that appropriate for this situation I found out the other day that you can also use the delete keyword to remove an item from an array if you don't need to alter the size of the array e.g.

    var myArray = [1,2,3];
    
    delete myArray[1];
    
    console.log(myArray[1]); //undefined
    
    console.log(myArray.length); //3 - doesn't actually shrink the array down
    

提交回复
热议问题