[ES6] Array.findIndex()

In es5, you can use indexOf to get the index of one item in an array.

 

In es6, you can use findIndex(), which is more prowful:

[NaN].indexOf(NaN) 
// -1

[NaN].findIndex(y => Object.is(NaN, y))
//0

 

You can use with splice() function:

 _cartItems.splice( _cartItems.findIndex( i => i === item ), 1 );

 

posted @ 2015-11-12 03:16  Zhentiw  阅读(598)  评论(0编辑  收藏  举报