当前位置:网站首页>Js array method is summarized
Js array method is summarized
2022-08-03 15:14:00 【quiet benevolence】
1.some()方法
总结:
/* 1.some 方法不会改变原数组 2.someThe method loops through the elements of the compound condition and returnstrue,否则就返回false 3.someThe method does not iterate over an empty array machine **/
let arr=[1,2,3,4,5,6,7,8];
let hasItem1= arr.some(item=>{
return item>4
})
let hasItem2= arr.some(item=>{
return item>20
})
console.log(hasItem1,hasItem2)
2.every()方法
总结:
/** 1.everyThe method is executed for each item in the arraycallback函数,并且,All items are returned only if they meet the conditionstrue 否则,返回false 2.every也不会改变原数组 */
let arr=[1,2,3,4,5,6,7,8];
let arr2 = arr.every(item=>{
return item>4
})
let arr3 = arr.every(item=>{
return item>10
})
3.filter()方法
总结:
/** 1.filterIterates over each item in the array,And it will put the data of the compound condition into a new array and return it 2.没有符合条件的,则返回一个空数组 */
let arr=[1,2,3,4,5,6,7,8];
let arr4= arr.filter(item=>{
return item>4
})
let arr5= arr.filter(item=>{
return item>20
})
console.log(arr4)
console.log(arr5)
4.map()方法
总结:
/** 1.mapIterates over each item in the array,并且返回一个新的数组 2.map不会检测空数组 */
let arr=[1,2,3,4,5,6,7,8];
let arr6=arr.map(item=>{
return item+2
})
console.log(arr6)
5.reverse()方法
let arr=[1,2,3,4,5,6,7,8];
// reverse() 方法 The data inside the array is reversed Change the data in the original array
let arr7= arr.reverse();
//返回的结果便是 8,7,6,5,4,3,2,1
6.pop()方法
总结:
/** Removes and returns the last item of the array */
let arr8= arr.pop();
console.log(arr8)
console.log(arr)
7.shift()方法
总结:
/** shift Removes and returns the first element of the array */
let arr9= arr.shift();
console.log(arr9)
console.log(arr)
8.push()方法
总结:
/** 在数组后面pushEnter one or more items of data */
let arr10= arr.push(12,17,18,19);
console.log(arr10)
console.log(arr10)
9.unshift()方法
总结:
/** Insert one or more items of data in front of the array */
arr.unshift(11,14,15,16);
console.log(arr)
10.slice()方法
//Intercept some data of the array (开始下标,结束下标),Do not write closing subscripts,It means to truncate to the end at the beginning subscript position
let arr11=arr.slice(1,4)
//也可以用-1截取最后一项
let arr12=arr.slice(-1);
//Some have said yes before 可以截取 (-1,4)intercept,我没有成功,It shows empty here,I hope someone who knows can give me some guidance.
11.sort()方法
总结:
/** 1.// sortSorting generally converts elements in an array into strings,比较字符串的Unicode 位点进行排序 2.Arrays can be sorted in ascending and descending order */
let arr20= arr.sort((a,b)=>a-b); //升序
console.log(arr20)
let arr21= arr.sort((a,b)=>b-a); //降序
console.log(arr21)
12.concat()方法
let arr1=[4,5];
let arr=[1,2,3]
let arr2=arr.concat(arr1)
arr2的结果就是 1,2,3,4,5
The above is what we need nowjsArray of some commonly used methods.If there are errors, you can leave a message to discuss
边栏推荐
猜你喜欢
Mysql 生成排序序号
[The Beauty of Software Engineering - Column Notes] 36 | What exactly do DevOps engineers do?
【R语言科研绘图】--- 柱状图
方舟生存进化开服需要多少钱
2021年12月电子学会图形化四级编程题解析含答案:新冠疫苗接种系统
Detailed explanation of cloud hard disk EVS and how to use and avoid pits [HUAWEI CLOUD is simple and far]
QT之Mysql驱动
今日睡眠质量记录75分
How to use redis
A high-performance creation book, ASUS Dreadnought Pro15 2022 is completely enough for daily photo editing and editing!
随机推荐
DeepLink在转转的实践
MMA安装及使用优化
问题9:为什么有边界值的测试?
2021年12月电子学会图形化四级编程题解析含答案:聪明的小猫
PAT乙级-B1013 数素数(20)
ubiquant量化竞赛
力扣1206. 设计跳表--SkipList跳表是怎么跳的?
FATFS | 中文显示 | 长文件名
指令重排以及案例
未来无法预料
sql注入之报错注入(精简详细)
【周报】2022年7月31日
使用虚幻引擎自动化工具实现自动化部署
【FPGA教程案例44】图像案例4——基于FPGA的图像中值滤波verilog实现,通过MATLAB进行辅助验证
cnpm 安装成功后提示不是内部和外部命令,也不是可运行的命令解决方案
PAT乙级-B1014 福尔摩斯的约会(20)
问题10:注册页面的易用性测试?
Use Typora+EasyBlogImageForTypora to write a blog and upload pictures quickly without a picture bed
PAT乙级-B1016 部分A+B(15)
技术分享 | 接口自动化测试如何搞定 json 响应断言?