当前位置:网站首页>数组合并方法:concat( )
数组合并方法:concat( )
2022-07-19 05:04:00 【一个水瓶座程序猿.】
JavaScript > 标准内置对象 > 数组 > Array.prototype.concat( )
concat()
方法用于 合并
两个或多个数组。此方法会返回一个新的数组,不会改变原有数组
语法:
- 二合一:Array.concat( value0 )
- 三合一:Array.concat( value0 , value1 )
- 多合一:Array.concat( value0 , value1 , … ,valueN )
参数:
valueN:要连接成新数组的数组或值
案例:
// 定义两个数组
const arr1 = ['a','b','c']
const arr2 = ['d','e','f']
// 使用数组的 concat 方法,将两个数组合并为一个数组
const arrResult = arr1.concat(arr2)
console.log(arrResult); // (6) ['a', 'b', 'c', 'd', 'e', 'f']
// 定义三个数组
const num1 = [1,2,3]
const num2 = [4,5,6]
const num3 = [7,8,9]
// 使用数组的 concat 方法,将三个数组合并为一个数组
const numberArr = num1.concat(num2,num3)
console.log(numberArr); // (9) [1, 2, 3, 4, 5, 6, 7, 8, 9]
边栏推荐
猜你喜欢
随机推荐
仿京东产品放大镜效果---js基础
C语言中动态内存的开辟
学习日记5-C语言函数的应用
ZABBIX agent adds a user-defined monitoring item -- Ping to destination IP link monitoring
C language program environment and preprocessing
Esp8266 -- temperature and humidity monitoring code dht-11 (web page display)
What if the game needs to be reinstalled after the steam folder is moved
堆堆排序及堆的相关操作
淘宝flexible.js文件实现弹性布局
学习日记1
bgr与rgb相互转换
[yolov5 realizes mobile phone detection]
练习提升C语言-1
更易上手的C语言入门级芝士 (3) 常见关键字+define+指针+结构体(超详细)
练习题(1)创建一个集合c1,存放元素“one“,“two“,“three“
C程序中的函数递归
自定义类型:结构体,位段,枚举,联合
scroll系列
三子棋游戏
Target detection partition data set