一个重要的方法 indexOf

如果数组中有你要查询的参数,则会返回一个 1,
[‘a’, ‘b’, ‘c’, ‘a’].indexOf(‘a’) // 1
如果数组中没有你想要的查询的参数,则会返回一个 -1
[‘a’, ‘b’, ‘c’, ‘a’].indexOf(‘d’) // -1
[‘a’, ‘b’, ‘c’, ‘a’].indexOf(‘a’, 1) // 3
** NaN 是个特例**
[NaN].indexOf(NaN) // -1

这里在后期学框架的时候会广泛的使用,建议可以重视一下此方法

猜你喜欢

转载自blog.csdn.net/weixin_43627806/article/details/89812609