当前位置:网站首页>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
边栏推荐
- AcWing 1148. 秘密的牛奶运输 题解(最小生成树)
- Installation of gazebo & connection with ROS
- 736. LISP syntax parsing: DFS simulation questions
- Make Jar, Not War
- Dark horse notes - exception handling
- Baidu flying general BMN timing action positioning framework | data preparation and training guide (Part 1)
- 前置机是什么意思?主要作用是什么?与堡垒机有什么区别?
- Mysqlbackup restores specific tables
- ZOJ Problem Set – 2563 Long Dominoes 【如压力dp】
- Telnet,SSH1,SSH2,Telnet/SSL,Rlogin,Serial,TAPI,RAW
猜你喜欢
随机推荐
永久的摇篮
Appium automation test foundation uiautomatorviewer positioning tool
图片打水印 缩放 和一个输入流的转换
剑指 Offer II 035. 最小时间差-快速排序加数据转换
Wood extraction in Halcon
拖拽改变顺序
What does security capability mean? What are the protection capabilities of different levels of ISO?
C language instance_ three
AcWing 344. Solution to the problem of sightseeing tour (Floyd finding the minimum ring of undirected graph)
Let's see how to realize BP neural network in Matlab toolbox
云呐|工单管理办法,如何开展工单管理
What does front-end processor mean? What is the main function? What is the difference with fortress machine?
C language instance_ two
The cradle of eternity
mongodb查看表是否导入成功
Metauniverse urban legend 02: metaphor of the number one player
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
数据手册中的词汇
免费白嫖的图床对比
Hutool post requests to set the body parameter to JSON data