toUpperCase; //转化为大写
toLowerCase; //转化为小写
split //分割字符串成数组 str.split(''); str.split(); 1,第一个为替换字符 2,显示个数
数组截断:
var array = [1,2,3,4,5,6];
console.log(array.slice(-1)); // [6] console.log(array.slice(-2)); // [5,6] console.log(array.slice(-3)); // [4,5,6]合并数组
2 3 | var array1 = [1,2,3]; var array2 = [4,5,6]; console.log(array1.concat(array2)); |
将nodelist通过[].slice.call(elements)转化为数组
2 3 | var elements = document.querySelectorAll("p"); // NodeList var arrayElements = [].slice.call(elements); // Now the NodeList is an array var arrayElements = Array.from(elements); |
数组重组
2 | var list = [1,2,3]; console.log(list.sort(function() { Math.random() - 0.5 })); |
数组合并
var list = [1,2,3];
var add=[5,6,7]; var arr=[]; document.write(arr.concat(list,add));