創(chuàng)建數(shù)組:
var arrayObj = new Array();
arrayObj. push([item1 [item2 [. . . [itemN ]]]]);// 將一個或多個新元素添加到數(shù)組結尾,并返回數(shù)組新長度
數(shù)組轉(zhuǎn)字符串
var arr = [1,2,3,4,'巴德','merge'];
var str = arr.join(',');
console.log(str); // 1,2,3,4,巴德,merge
字符串轉(zhuǎn)數(shù)組
var str = '1,2,3,4,巴德,merge';
var arr = str.split(',');
console.log(arr); // ["1", "2", "3", "4", "巴德", "merge"] 數(shù)組
console.log(arr[4]); // 巴德
數(shù)組格式化轉(zhuǎn)數(shù)組:
var str = '1,2,3,4,巴德,merge';
var arr = str.split(',');
console.log(arr); // ["1", "2", "3", "4", "巴德", "merge"] 數(shù)組
console.log(arr[4]); // 巴德
數(shù)組轉(zhuǎn)數(shù)組格式化:
var strify = JSON.stringify(arr);
console.log(strify); // ["1", "2", "3", "4", "巴德", "merge"] 字符串
字符串轉(zhuǎn)數(shù)組:
var arrParse = JSON.parse(strify);
console.log(arrParse); // ["1", "2", "3", "4", "巴德", "merge"] 數(shù)組
發(fā)表評論