zoukankan      html  css  js  c++  java
  • indexOf()

    索引辨析

    indexOf() 

    在字符串中寻找索引

    1 const paragraph = 'The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?';
    2 const searchTerm = 'dog';
    3 const indexOfFirst = paragraph.indexOf(searchTerm);
    console.log('The index of the first "' + searchTerm + '" from the beginning is ' + indexOfFirst);
    // expected output: "The index of the first "dog" from the beginning is 40"

    findIndex()

    var ages = [3, 10, 18, 20];
     
    function checkAdult(age) {
        return age >= 18;
    }
     
    function myFunction() {
        document.getElementById("demo").innerHTML = ages.findIndex(checkAdult);  //2
    }

    寻找的的是数组中元素的索引

  • 相关阅读:
    CSP2018-09
    CSP2018-03
    CSP2017-12
    CSP2017-09
    CSP2017-03
    CSP2016-12
    [算法设计与分析] 奶酪 (并查集)
    5555
    阿超
    结对作业
  • 原文地址:https://www.cnblogs.com/George19950505/p/12603417.html
Copyright © 2011-2022 走看看