废话不多说直接上代码,至于它的定义说明,可以通过网W3school这些网站查看。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script type="text/javascript">
var colors=["red","blue","purple","yelllow"];
var colors2=colors.concat("white","black");
var colors3=colors2.concat(["brown"]);
var colors4=colors3.concat("green",["tan"]);
var colors5=colors4.concat("syan",["gray",["yellowgreen"]]);
var colors6=colors5.slice(1);
var colors7=colors5.slice(1,4);
var colors8=colors.slice(-2,-1);
var colors9=colors.slice(-2);
var colors10=colors.slice(-3,-1);
var colors11=colors.slice(-3,-2);
var colors12=colors.splice(0,2);
var colors13=colors.splice(0,1,"pink","stone");
document.write("+++++concat()方法+++++++");
document.write("<br>");
document.write(colors);
document.write("<br>");
document.write(colors2);
document.write("<br>");
document.write(colors3);
document.write("<br>");
document.write(colors4);
document.write("<br>");
document.write(colors5);
document.write("<br>");
document.write("+++++slice()方法+++++++");
document.write("<br>");
document.write(colors6);
document.write("<br>");
document.write(colors7);
document.write("<br>");
document.write(colors8);
document.write("<br>");
document.write(colors9);
document.write("<br>");
document.write(colors10);
document.write("<br>");
document.write(colors11);
document.write("<br>");
document.write("+++++splice()方法+++++++");
document.write("<br>");
document.write(colors12);
document.write("<br>");
document.write(colors13);
document.write("<br>");
document.write(colors);
</script>
</body>
</html>
ouput:
+++++concat()方法+++++++
pink,stone,yelllow
red,blue,purple,yelllow,white,black
red,blue,purple,yelllow,white,black,brown
red,blue,purple,yelllow,white,black,brown,green,tan
red,blue,purple,yelllow,white,black,brown,green,tan,syan,gray,yellowgreen
+++++slice()方法+++++++
blue,purple,yelllow,white,black,brown,green,tan,syan,gray,yellowgreen
blue,purple,yelllow
purple
purple,yelllow
blue,purple
blue
+++++splice()方法+++++++
red,blue
purple
pink,stone,yelllow