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

风格不统一 提交于 2019-12-03 12:29:26

Check this performance test out. It's has not that much to do with Angular, but more with JavaScript. If you're able just go for the fastest method available :)

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

In case you know the index using splice would be an O(1) operation while using filter is an O(n) operation.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!