findIndex 对数组执行遍历,查询对应值得下标

    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <title>Document</title>
    7. </head>
    8. <body>
    9. <!--
    10. findIndex 对数组执行遍历,查询对应值得下标
    11. -->
    12. <script>
    13. var arr = [1,2,3,2];
    14. var index = arr.findIndex(item=>{
    15. return item == 2;
    16. })
    17. console.log(index);//1
    18. </script>
    19. </body>
    20. </html>