<script type="text/javascript">
var arr1 = [1,2,3,4];
console.log(arr1.slice(1,3));
console.log(arr1.join(""))//1234
console.log(arr1.join("a"));//1a2a3a4 join()转为字符串
arr1.unshift("a");//unshift()往数组的前面添加元素
console.log(arr1);//["a", 1, 2, 3, 4]
arr1.shift("a");//shift()删除数组最前面的元素
console.log(arr1);//[1, 2, 3, 4]
arr1.push("b");//push()往数组的后面添加元素
console.log(arr1);//[1, 2, 3, 4, "b"]
arr1.pop();//pop()删除数组最后一位
console.log(arr1);//[1, 2, 3, 4]
//splice() 3个参数,第一个参数是指下标,第二项是指删除几位,0就是不删除,
//第三个参数指要添加的元素
var arr2 = [1,2,3,4]
arr2.splice(0,2,"s");
console.log(arr2);
var arr3 = [1,2,3,4]
console.log(arr3.indexOf(1));//0
console.log(arr3.reverse());//[4, 3, 2, 1] 倒序
//**字符串倒叙
var str = "abccd";
var str1 = str.split("").reverse().join("");
console.log(str1);//dccba
</script>
网友评论