当前位置:网站首页>[ES6] explain in detail the common objects and other methods of set and array (full version)
[ES6] explain in detail the common objects and other methods of set and array (full version)
2022-07-19 05:13:00 【Create splendid -- hand in hand with you】
The first part :Set data structure :
ES6 Provides a new data structure Set. It's like an array , But the values of the members are unique , There are no duplicate values .
Definition :const s = new Set();
initialization :const set = new Set([1, 2, 3, 4, 4]);//{1, 2, 3, 4}
Example method :
const s = new Set();
s.add(1).add(2);// add value
s.delete(2);// Delete value , It's not an index
console.log(s.has(2));//set Yes no 2, There is a return true
console.log(s.clear());// Clear all values
The second part :Array Common objects of
1,array Extension method of Processing first and then returning a new array
// Array map()
// let arr= [1,2,3,4]
// let newarray = arr.map((item)=>{
// return item + 2;
// })
// console.log(newarray)
The result is :
0: 3
1: 4
2: 5
3: 6
length: 4
1: Find the maximum value in the array ( cut )
let arr = [1,2,3,4,5]
let newarray = arr.reduce((total,values)=>{
return total<values?values:total;
})
console.log(newarray)
The final result is : The maximum value is 5
2, Array filter()
// let arr = [1,2,3,4,5,6]
// let newarray = arr.filter((item)=>{
// return item > 5;
// })
// console.log(newarray)
// The final return value is 6
4:fill fill ( Usage is ('x',1,3) first x Indicates the content after replacement The second acquisition parameter is from which position The third value refers to the end of the third digit ( But it does not include the current bit ))
// let arr = [1,2,3,4,5]
// arr.fill('x',1,3);
// console.log(arr)
// The final return value is 1,x,x,4,5
The third part : Other methods
1,in Determine whether the element is an array ( object ) Properties of
// let arr = ['a','b','c','d']
// console.log(a in arr);// The return is false Non placed here a It's the subscript of the array element , If you place the subscript of the element, you can print
// let arr = ['a','b','c','d']
// console.log(4 in arr)// The return is true
2,some() Method is used to detect whether the elements in the array meet the specified conditions ( Function provides )
/ / var ages = [3, 10, 1, 1];
// var flag = ages.some(v=> v>2);
// console.log(flag);
// The final result is true
3:split Put the string according to “ Separator ” Converted to an array join Divide the array into “ Separator ” Concatenate into a string
// let arr = 'abcde';
// let arr1 = arr.split('');
// console.log(arr1);
// // The output is ['a', 'b', 'c', 'd', 'e']
// let arr2 = arr1.join('-');
// console.log(arr2);
// The output is a-b-c-d-e
4:Array.of Responsible for the A pile of text is converted into an array
// let a=1;
// let b=2;
// let c=3;
// let arr1 = Array.of(a,b,c);
// console.log(arr1);
The final result : [1, 2, 3]
边栏推荐
猜你喜欢
![[2022 10th Teddy Cup Challenge] Title A: complete version of pest identification (general idea. Detailed process and code and results CSV in compressed package)](/img/e6/beea0bb0a9f4b41206c6fcb130fdfd.png)
[2022 10th Teddy Cup Challenge] Title A: complete version of pest identification (general idea. Detailed process and code and results CSV in compressed package)

Hire the server, and the pytorch environment training yolov5 model tutorial deployed on pycharm professional edition. Server environment installation library file:

User management - restrictions

Asynchronous data SMS verification code

vscode终端无法使用解决的办法

About the current response, the method getoutputstream() has been called

Word2Vec原理及应用与文章相似度(推荐系统方法)

C语言初学者之初识代码专项练习

es6新增-数组/对象的解构赋值

微信小程序云开发使用方法-1
随机推荐
01_电影推荐(ContentBased)_物品画像
多功能(实现)封装函数
C语言练习2
滚动轮加载的两种js方法及模态框拖拽归总
读论文《SNUNet-CD: A Densely Connected Siamese Network for Change Detection of VHR Images》
第十届泰迪杯数据挖掘挑战赛A题害虫识别YOLOv5模型代码(已跑通,原创作品,持续更新)
es6新增-数组部分
实习项目1-个性化主页配置
决策树原理和案例应用-泰坦尼克号生存预测
C语言初学者之初识代码专项练习
uni-app 条件编译#ifdef #endif 兼容多个终端
IDL 6S查找表
实习项目2-主页配置-我的数据模块
[2022 10th Teddy Cup Challenge] Title A: complete version of pest identification (general idea. Detailed process and code and results CSV in compressed package)
Getting started with harmonios
使用js中的(offset,page)实现登录效果
【C语言—零基础第十三课】字符串的奥秘
mysql数据库实验实训5,数据查询yggl数据库查询(详细)
User management - restrictions
使用js实现安居客二级菜单及(注意事项和问题点演示)完整版