Remove object in array using filter and splice which one is best approach in JavaScript?

前端 未结 5 1572
抹茶落季
抹茶落季 2020-12-31 09:18

Hi I delete an object in an array using two approaches:- splice and filter.

splice code here:-

(this.myArray).splice((this.myArray).indexOf(myobjec         


        
5条回答
  •  忘掉有多难
    2020-12-31 09:57

    Array.splice - will change the Array itself. (use: myArray.splice)
    Array.filter - will return the filtered Array. (use: myFilteredArray = Array.filter)
    This is a test result on an Array of 30 small objects. I ran it on jsbence.me:

提交回复
热议问题