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

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

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

2017.02.25 | 1763閱讀 | 0條評(píng)論 | javascript

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

var arrayObj = new Array();

arrayObj. push([item1 [item2 [. . . [itemN ]]]]);// 將一個(gè)或多個(gè)新元素添加到數(shù)組結(jié)尾,并返回?cái)?shù)組新長(zhǎng)度


數(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ā)表評(píng)論