当前位置:网站首页>Js array commonly used API
Js array commonly used API
2022-07-29 11:49:00 【IT worker】
var color = [“red”,”green”,”blue”];
var color2 = [“yellow”,”black”,”brown”];
var color3 = color.concat(color2); // concat is the content of the array passed in the parameter spliced after the caller,不修改原数组
var color4 = color.toString();// Arrays are converted to comma-connected strings
var color5 = color.join(‘+’);// Convert data to a string concatenated with parameters
var color6 = “red,green+blue”;
var color7 = color6.split(‘+’);// Convert a string to an array by argument
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 a piece of the original array,From the start position of the start parameter,to the end of the parameter, 不包括结束位置, 不改变原数组
var arr = [{“name”: “aa”}, {“age”: 12}];
console.log(arr.slice(1, 2)); // [{“age”: 12}]
console.log(arr); // [{“name”: “aa”}, {“age”: 12}]
// splice() Truncate a segment of the original array and return a new array, 修改原数组, [起始下标, 切割个数]
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]
边栏推荐
- 微信发红包测试用例
- HMS Core Discovery 16 review | with tiger mound, embracing new AI "voice" state
- RediSearch 发布 v2.4.10 & v2.4.11 版本
- 微信云托管入门与实践
- SkiaSharp of WPF custom painting to bounce ball (case)
- 解决idea在debug模式下变得非常慢的问题
- 学习周刊-总第64期-一个v2ex风格的开源论坛程序
- QT's user-defined interface (borderless and movable)
- SkiaSharp 之 WPF 自绘 弹动小球(案例版)
- c语言:来实现一个小程序n子棋(已五子棋为例)
猜你喜欢
随机推荐
How to use grep to display file names and line numbers before matching lines
【day04】IDEA、方法
使用Tenserboard可视化深度学习训练过程
从零开始Blazor Server(3)--添加cookie授权
AI model risk assessment Part 2: core content
INVALID_ARGUMENT : Invalid rank for input: modelInput Got: 3 Expected: 4 Please fix either the input
[image detection] Research on cumulative weighted edge detection method based on gray image, with matlab code
2022 latest WiFi master applet independent version 3.0.8
After connect and SQL join in on conditions and where
学习周刊-总第64期-一个v2ex风格的开源论坛程序
What is kubernetes custom resource definition (CRD)?
QML(一):自定义圆角按钮的处理
IPv6 Foundation
微信怎么知道别人删除了你?批量检测方法(建群)
【表达式计算】表达式计算问题的通用解法(练习加强版,含总结)
PL/SQL 面向对象
Kubernetes基本概念
Starrocks technology insider: how to have both real-time update and fast query
Golang realizes file upload and download
c语言:来实现一个小程序n子棋(已五子棋为例)