当前位置:网站首页>JS how to quickly create an array with length n
JS how to quickly create an array with length n
2022-07-07 01:41:00 【Idle fish_ JavaScript】
purpose
- Quickly create a loop N Array of times
- When simulating false data , Quick creation length is n False data of
- …
Method 1
- Create a The length is 10000, Value is empty Array of
const a = new Array(10000).fill(''); // (10000) ['', '','', '', '' ....................., '']

- Quickly create the specified content ? Take the index as an example
const a = new Array(10000).fill('').map((val, i) => i); // (10000) [0, 1,2, 3, 4 ....................., 9999]

Method 2
- Create a The length is 10000, Value is empty Array of
const c = Array.from(new Array(10000), () => ''); // (10000) ['', '','', '', '' ....................., '']

- Create a The length is 10000, The value is index Array of
// (...cont) => cont This cont Is to integrate all parameters of this function, all parameters, all parameters ( Merge into an array by cont );
// (...cont) => cont It can also be written here, here, here (val, i) => [val, i];
const c = Array.from(new Array(10000), (...cont) => cont[1]); // (10000) [0, 1,2, 3, 4 ....................., 9999]
const c = Array.from(new Array(10000), (val, i) => i); // (10000) [0, 1,2, 3, 4 ....................., 9999]


summary
- Mode one : Create array , Fill empty string , then map Loop back the newly processed array .
- Mode two : adopt Array Of form Static methods pass two parameters , The first is an array , The second parameter is the callback function for processing various values
边栏推荐
- Yunna | work order management measures, how to carry out work order management
- Gin introduction practice
- Yunna | work order management software, work order management software app
- ZOJ problem set – 2563 long dominoes [e.g. pressure DP]
- 2022 Google CTF SEGFAULT LABYRINTH wp
- Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
- AcWing 361. 观光奶牛 题解(spfa求正环)
- 域分析工具BloodHound的使用说明
- 安全保护能力是什么意思?等保不同级别保护能力分别是怎样?
- 设置Wordpress伪静态连接(无宝塔)
猜你喜欢

设置Wordpress伪静态连接(无宝塔)

2022 Google CTF SEGFAULT LABYRINTH wp

从底层结构开始学习FPGA----FIFO IP的定制与测试

Make Jar, Not War

免费白嫖的图床对比

1123. The nearest common ancestor of the deepest leaf node

LeetCode. 剑指offer 62. 圆圈中最后剩下的数

AcWing 345. 牛站 题解(floyd的性质、倍增)

Js逆向——捅了【马蜂窝】的ob混淆与加速乐

Set WordPress pseudo static connection (no pagoda)
随机推荐
AcWing 1141. 局域网 题解(kruskalkruskal 求最小生成树)
Match VIM from zero (0) -- Introduction to vimscript
AcWing 1141. LAN problem solving (kruskalkruskal finding the minimum spanning tree)
云呐|工单管理软件,工单管理软件APP
Taro applet enables wxml code compression
Reptile practice (VI): novel of climbing pen interesting Pavilion
Mysqlbackup restores specific tables
糊涂工具类(hutool)post请求设置body参数为json数据
C语言实例_2
Appium自动化测试基础 — uiautomatorviewer定位工具
拖拽改变顺序
grep查找进程时,忽略grep进程本身
JS ES5也可以创建常量?
Installation of gazebo & connection with ROS
编译命令行终端 swift
字符串转成日期对象
从底层结构开始学习FPGA----FIFO IP的定制与测试
454-百度面经1
1123. 最深叶节点的最近公共祖先
Can't you understand the code of linked list in C language? An article allows you to grasp the secondary pointer and deeply understand the various forms of parameter passing in the function parameter