zoukankan      html  css  js  c++  java
  • 不使用 loop,创建一个长度为 100 的数组

    
    
    console.log(Array(100).join(",").split(",").map(function(key,index){return index;}));

    console.log(Array.apply(null, {length: 100}).map(Number.call, Number));

    console.log(Object.keys(Array.apply(null, {length: 100})));

    console.log(Array.from({length:100}, function(value, index){ return index }));

    console.log(Object.keys(Array(100).toString().split(",")));


    1. array.map(callbackfn(value, index, array), thisArg); 

    
    

    参数

    定义

    array1

    必选。  一个数组对象。  

    callbackfn

    必选。  最多可以接受三个参数的函数。  对于数组中的每个元素,map 方法都会调用 callbackfn 函数一次。  

    thisArg

    可选。   callbackfn 函数中的 this 关键字可引用的对象。  如果省略 thisArg,则 undefined 将用作 this 值。 



    2. Object.keys(object)

    参数

    定义

     

    Object

     

    必需。包含属性和方法的对象。这可以是您创建的对象或现有文档对象模型 (DOM) 对象。



    3. Array.from(arrayLike[, mapFn[, thisArg]])

    参数

    定义

    arrayLike

    想要转换成真实数组的类数组对象或可遍历对象。

    mapFn

    可选参数,如果指定了该参数,则最后生成的数组会经过该函数的加工处理后再返回。

     thisArg  可选参数,执行 mapFn 函数时 this 的值。
    
    


    参考:https://github.com/N-ZOO/everycode/issues/19


  • 相关阅读:
    0326系统按钮添加权限的工作(jsp权限写法)
    0321菜单数据
    ztree树的递归
    前端padding margin
    解决1像素边框问题
    水平垂直居中
    移动端css公共样式
    tap方法改良this指向
    移动端常见问题
    前端笔记(兼容)
  • 原文地址:https://www.cnblogs.com/xiaochechang/p/5922193.html
Copyright © 2011-2022 走看看