当前位置:网站首页>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]
边栏推荐
- 谷歌“消灭” Cookie 计划延至 2024 年
- 测试环境要多少,从现实需求说起
- [image detection] Research on cumulative weighted edge detection method based on gray image, with matlab code
- puzzle(017.5)联动归位
- Learning with Recoverable Forgetting阅读心得
- 怎么以管理员身份运行cmd?以管理员身份运行cmd方法介绍
- HMS Core音频编辑服务音源分离与空间音频渲染,助力快速进入3D音频的世界
- PL/SQL 事务
- Self collection online computer wallpaper PHP source code v2.0 adaptive end
- GBase8s Informix Dodker 高可用集群自恢复集群启动命令oninitdb的设计与实现
猜你喜欢

Out-of-the-box problem-solving thinking, putting a "rearview mirror" on the unconscious life

如何使用 grep 跨多行查找模式匹配

Lucky draw system with background source code

7月3日文: 表面上有危险,实属安全周期,大概率会快速上扬的个股

Starrocks technology insider: how to have both real-time update and fast query

Building and sharing the root of the digital world: Alibaba Cloud builds a comprehensive cloud-native open source ecosystem

考完PMP后有什么益处

【Untitled】

2022年企业直播行业发展洞察

Proficient in audio and video development can really do whatever you want
随机推荐
LED透明屏和LED玻璃显示屏区别
Std:: vector copy, append, nested access
WPF 实现平移控件
PL/SQL 事务
宝塔快速搭建自适应咖啡网站模板与管理系统源码实测
解决idea在debug模式下变得非常慢的问题
three.js 报错信息 RGBELoader.js:46 RGBELoader Bad File Format: bad initial token
Package delivery (greedy)
c语言:来实现一个小程序n子棋(已五子棋为例)
Based on the flask to write a small shopping mall project
HMS Core Discovery第16期回顾|与虎墩一起,玩转AI新“声”态
On CompareTo method in string
【一起学Rust | 基础篇】Rust基础——变量和数据类型
LMO·3rd - 报名通知
Starrocks technology insider: how to have both real-time update and fast query
黑马四小时入门学习记录-2|本地应用
[image detection] Research on cumulative weighted edge detection method based on gray image, with matlab code
Deep understanding of c # nullable types
路径依赖 - 偶然决策导致的依赖。
【Unity3D】角色控制器(CharacterController)