<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>拆分和合并</title>
</head>
<body>
<script>
//字符串转成数组
let str="hxj,ydc";
let arr=str.split(",");
console.log(arr);// ["hxj", "ydc"]
str=arr.join(",");
console.log(str);//hxj,ydc
//数组连接
let a=[1,2,3,4];
let b=[4,5,6];
let c=[6,7,8];
//a=a.concat(b,c);
//console.log(a);//[1, 2, 3, 4, 4, 5, 6, 6, 7, 8]
//使用点语法连接数组
a=[...a,...b,...c];
console.log(a);//[1, 2, 3, 4, 4, 5, 6, 6, 7, 8]
//数组元素内部的复制
//arr.copyWithin(target,start,end),
//target复制到目标索引,复制内容的索引[start,end);
let fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi", "Papaya"];
fruits.copyWithin(2, 0, 2);
console.log(fruits);// ["Banana", "Orange", "Banana", "Orange", "Kiwi", "Papaya"]
</script>
</body>
</html>
网友评论