龍巖易富通網(wǎng)絡科技有限公司

龍巖小程序開發(fā),龍巖分銷系統(tǒng)

js 常用數(shù)組、字符串、json轉(zhuǎn)換

2017.02.25 | 1832閱讀 | 0條評論 | javascript

創(chuàng)建數(shù)組:

var arrayObj = new Array();

arrayObj. push([item1 [item2 [. . . [itemN ]]]]);// 將一個或多個新元素添加到數(shù)組結(jié)尾,并返回數(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ā)表評論