当前位置:网站首页>js 数组常用API
js 数组常用API
2022-07-29 11:42:00 【IT工作者】
var color = [“red”,”green”,”blue”];
var color2 = [“yellow”,”black”,”brown”];
var color3 = color.concat(color2); // concat 是将参数传递进来的数组内容 拼接到调用者后面,不修改原数组
var color4 = color.toString();// 数组转换成以逗号相连的字符串
var color5 = color.join(‘+’);// 将数据转换成以参数相连的字符串
var color6 = “red,green+blue”;
var color7 = color6.split(‘+’);// 将字符串按参数转换成数组
console.log(color); // [“red”, “green”, “blue”]
console.log(color2); // [“yellow”, “black”, “brown”]
console.log(color3); // [“red”, “green”, “blue”, “yellow”, “black”, “brown”]
console.log(color4); // red,green,blue
console.log(color5); // red+green+blue
console.log(color7); // [“red,green”, “blue”]
// slice() copy 原数组的一块,从开始参数的开始位置,到参数的结束位置, 不包括结束位置, 不改变原数组
var arr = [{“name”: “aa”}, {“age”: 12}];
console.log(arr.slice(1, 2)); // [{“age”: 12}]
console.log(arr); // [{“name”: “aa”}, {“age”: 12}]
// splice() 截取原数组的一段返回新数组, 修改原数组, [起始下标, 切割个数]
var arr1 = [1,2,3];
console.log(arr1.splice(0,2)); // [1, 2]
console.log(arr1) // [3]
// reverse() 反转数组 改变原数组
var arr2 = [1,5,4];
var arr22 = arr2.reverse();
console.log(arr22); // [4, 5, 1]
console.log(arr2); // [4, 5, 1]
边栏推荐
- 黑马四小时入门学习记录-3|网络应用
- INVALID_ ARGUMENT : Invalid rank for input: modelInput Got: 3 Expected: 4 Please fix either the input
- Deep understanding of c # nullable types
- PL/SQL 面向对象
- 从零开始Blazor Server(3)--添加cookie授权
- Flink UDF 函数汇总
- 北京大学公开课重磅来袭!欢迎走进「AI for Science」课堂
- Gbase8s core data backup
- TCP and UDP
- Self collection online computer wallpaper PHP source code v2.0 adaptive end
猜你喜欢

DNS protocol, ICMP protocol, NAT technology

Self collection online computer wallpaper PHP source code v2.0 adaptive end

HMS Core音频编辑服务音源分离与空间音频渲染,助力快速进入3D音频的世界

Lucky draw system with background source code

2.1冒泡排序(Bubble Sorting)

多元宇宙:重塑新商业格局

1.4、栈

593. 有效的正方形

幸运抽奖系统带后台源码

How to use grep to find pattern matching across multiple lines
随机推荐
Starrocks technology insider: how to have both real-time update and fast query
【表达式计算】表达式计算问题的通用解法(练习加强版,含总结)
three.js 报错信息 RGBELoader.js:46 RGBELoader Bad File Format: bad initial token
自采集在线电脑壁纸php源码v2.0自适应端
puzzle(017.5)联动归位
解决idea在debug模式下变得非常慢的问题
如何开始为您的 Kubernetes 应用程序编写 Helm 图表
力扣sql刷题(四)
黑马四小时入门学习记录-2|本地应用
QML(一):自定义圆角按钮的处理
DNS protocol, ICMP protocol, NAT technology
【每日SQL打卡】DAY 26丨餐馆营业额变化增长【难度中等】
How to use grep to display file names and line numbers before matching lines
Dawei gbase8s cursor stability read esql test case
大伟 Golang之路
MySql启动、连接sqlog、主从复制、双机热备(开机时)
Building and sharing the root of the digital world: Alibaba Cloud builds a comprehensive cloud-native open source ecosystem
[image detection] Research on cumulative weighted edge detection method based on gray image, with matlab code
2022年企业直播行业发展洞察
XSS漏洞分析