美文网首页
数组扩展

数组扩展

作者: 牛耀 | 来源:发表于2018-09-27 23:07 被阅读0次
  1. Array.from(v) : 将伪数组对象或可遍历对象转换为真数组
  2. Array.of(v1, v2, v3) : 将一系列值转换成数组
  3. find(function(value, index, arr){return true}) : 找出第一个满足条件返回true的元素
  4. findIndex(function(value, index, arr){return true}) : 找出第一个满足条件返回true的元素下标
        let btns=document.getElementsByTagName('button');
        Array.from(btns).forEach(function(item,index){
            console.log(index);
        })
        let arr = Array.of(1,3,6,'axd',false);
        console.log(arr);//[object Array]: [1, 3, 6, "axd", false]
        let arr1 = [1,2,3,1,6,3,8,9];
        let result = arr1.find(function(item,index){
            return item >7;
        })
        console.log(result);//8
        let arr2 = [1,2,3,1,6,3,8,9];
        let result1 = arr1.findIndex(function(item,index){
            return item >9;
        })
        console.log(result1);//-1
        let result2 = arr1.findIndex(function(item,index){
            return item >5;
        })
        console.log(result2);//4

相关文章

  • 3.数组扩展

    1)cat函数扩展结果=cat(1或2,数组1,数组2) 3)水平连接扩展结果=horzcat(数组1,数组2,。...

  • ES6数组扩展

    二、数组扩展

  • ES6扩展

    字符串的扩展正则的扩展数值的扩展数组的扩展函数的扩展对象的扩展

  • 数组扩展

    扩展运算符(spread)是三个点(...) 将一个数组转为用逗号分隔的参数序列。 替代函数的 apply 方法 ...

  • 数组扩展

    Array.from(v) : 将伪数组对象或可遍历对象转换为真数组 Array.of(v1, v2, v3) :...

  • 数组扩展

    Array.of## Array.from## 把 伪数组 或者 集合 转为数组 类似map的功能 Array.f...

  • 数组扩展

    王先生定期给三家水果店送水果,小李开的小李水果店,小张开的小张水果店,小蔡开的小蔡水果店 小李的顾客喜欢苹果和香蕉...

  • 扩展:数组

    1. 返回值含义 返回值有时存在两种情况:合法值和非法值。如果有非法值的情况,通常使用一些特定的值指代特殊情况。例...

  • 数组扩展

    1,扩展运算符2,Array.from()3,Array.of()4,数组实例的 copyWithin()5,数组...

  • es6入门

    一、解构赋值 数组的解构赋值 二、 对象解构赋值 三、正则新特性 四、字符串扩展 五、数值扩展 六、数组扩展 七、...

网友评论

      本文标题:数组扩展

      本文链接:https://www.haomeiwen.com/subject/ihnyoftx.html