findIndex()

es6的findIndex()方法,返回数组找到项的索引

const index = newSelectedValues.findIndex(item => item === value)
newSelectedValues.splice(index,1)

区分一下数组的find()

数组实例的find方法,用于找出第一个符合条件的数组成员。它的参数是一个回调函数,所有数组成员依次执行该回调函数,直到找出第一个返回值为true的成员,然后返回该成员。如果没有符合条件的成员,则返回undefined。

猜你喜欢

转载自blog.csdn.net/weixin_43131046/article/details/121209081
今日推荐