当前位置:网站首页>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
边栏推荐
- 2022 Google CTF SEGFAULT LABYRINTH wp
- tansig和logsig的差异,为什么BP喜欢用tansig
- AcWing 361. 观光奶牛 题解(spfa求正环)
- Instructions for using the domain analysis tool bloodhound
- AI automatically generates annotation documents from code
- 736. LISP syntax parsing: DFS simulation questions
- 7.6 simulation summary
- Dark horse notes - create immutable sets and streams
- 长按按钮执行函数
- Baidu flying general BMN timing action positioning framework | data preparation and training guide (Part 2)
猜你喜欢
1123. 最深叶节点的最近公共祖先
Appium automation test foundation uiautomatorviewer positioning tool
Byte P7 professional level explanation: common tools and test methods for interface testing, Freeman
AcWing 1148. 秘密的牛奶运输 题解(最小生成树)
How to manage distributed teams?
The difference between Tansig and logsig. Why does BP like to use Tansig
盒子拉伸拉扯(左右模式)
今日问题-2022/7/4 lambda体中修改String引用类型变量
Yunna | work order management software, work order management software app
Make Jar, Not War
随机推荐
AI 从代码中自动生成注释文档
字符串转成日期对象
百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (下)
Drag to change order
图片打水印 缩放 和一个输入流的转换
分享一个通用的so动态库的编译方法
golang 基础 —— 数据类型
Baidu flying general BMN timing action positioning framework | data preparation and training guide (Part 2)
JVM 内存模型
Long press the button to execute the function
云呐-工单管理制度及流程,工单管理规范
WCF Foundation
Telnet,SSH1,SSH2,Telnet/SSL,Rlogin,Serial,TAPI,RAW
C语言实例_3
[signal and system]
JS es5 peut également créer des constantes?
JS ES5也可以創建常量?
swiper组件中使用video导致全屏错位
【C语言进阶篇】指针的8道笔试题
7.6模拟赛总结