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

前端 未结 5 1566
抹茶落季
抹茶落季 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 10:11

    I think that the main difference here is:

    • splice - lets you remove an element from this particular array
    • filter - won't touch the input array and will create and return new filttered array

    angular has nothing to do here and when it comes to speed, splice will win

    and small test as proof https://jsperf.com/array-splice-vs-array-filter/1

提交回复
热议问题