findIndex 对数组执行遍历,查询对应值得下标
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<!--
findIndex 对数组执行遍历,查询对应值得下标
-->
<script>
var arr = [1,2,3,2];
var index = arr.findIndex(item=>{
return item == 2;
})
console.log(index);//1
</script>
</body>
</html>