js_Array类型_操作方法
2021-04-10 06:28
标签:gre range 操作 log 返回 lis list 参数 影响 目录 js_Array类型_操作方法 标签:gre range 操作 log 返回 lis list 参数 影响 原文地址:https://www.cnblogs.com/Syinho/p/12397637.html
concat
var colors=["red","green","blue"];
var colors2=colors.concat("yellow",["black","brown"]);
console.log(`colors:${colors}`);//["red","green","blue"]
console.log(`colors2:${colors2}`);//["red","green","blue",yellow","black","brown"]
slice
var colors=["red","green","blue","black","brown"];
var colors2=colors.slice(1);
console.log(colors2);//["green","blue","black","brown"]
var colors3=colors.slice(1,4);
console.log(colors3);//["green","blue","black"]
splice
ex.删除第一项
var colors=["red","green","blue"];
var removed=colors.splice(0,1);//选中索引为1的项,以它为首删除1个项
console.log(removed);//["red"]
console.log(colors);//["green","blue"]
ex.删除连续的两项
var colors=["red","green","blue"];
var removed=colors.splice(1,2);//选中索引为1的项,以它为首删除2个项
console.log(removed);//["green","blue"]
console.log(colors);//["red"]
ex.删除一项,并在那个位置插入两项
var colors=["red","green","blue"];
var removed=colors.splice(1,1,"yellow","orange");
console.log(removed);//["green"]
console.log(colors);//["red","yellow","orange","blue"]
上一篇:Hadoop HDFS web
下一篇:xml与ajax1