var newArr = [1,2,3]; newArr instanceof Array; // true Array.isArray(newArr) ; // true //Array.isArray(newArr) 只支持ie9+,firefox 4+,safari 5+,opera 10.5+和chrome
4. 要素
var newArr = new Array(); // 创建数组 var newArr = new Array(3); // 创建数组并指定长度 var newArr = new Array(1,2,[3,4]); //创建数组并赋值
var newArr = new Array(); // 创建数组 var newArr = new Array(3); // 创建数组并指定长度 var newArr = new Array(1,2,[3,4newArr.push('A'); //6 newArr; // [1,2,3,4,5,'A'] newArr.unshift('B'); //7 newArr; // ['B',1,2,3,4,5,'A'] newArr.splice(2,0,'C'); // [] newArr; //["B", 1, "C", 2, 3, 4, 5, "A"]]); //创建数组并赋值
6. 配列のコピー
var newArr = [1,2,3,4,5]; newArr.pop(); //5 newArr; // [1,2,3,4] newArr.shift(); //1 newArr; // [2,3,4] newArr.splice(1,2); //[3,4] newArr; //[2]
7. 配列の並べ替え
var newArr = ['A','B','C','D','E']; newArr.slice(2); //["C", "D", "E"] newArr.slice(1,4); //["B", "C", "D"] newArr.concat('M'); //["A", "B", "C", "D", "E", "M"]
8 .配列
変換
rree
var newArr = ['A','B','C','D','E']; newArr.slice(0); //["A", "B", "C", "D", "E"] newArr.concat(); //["A", "B", "C", "D", "E"]
以上がJsの配列操作の基本的な方法を解説の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。