javascript - Asking for help with a basic question, how to implement the following operations on js arrays?
習慣沉默
習慣沉默 2017-06-14 10:54:01
0
6
716

How to convert the array as shown into:

["0","1","2","3","4","5","6","7","8","9","10"]

習慣沉默
習慣沉默

reply all(6)
漂亮男人

As The Code Do:

arr.join(',').split(','); 
Peter_Zhu

Create a new array, traverse the current array, and determine the length attribute of each item. If it is not greater than 1, put it into the array. If it is greater than 1, split('') and then concat it into the new array. Then just return the new array.

代言
const arr = ["0", "1", "2", "3,4,5,6", "7,8", "9,10"];
const arr2 = [];

arr.forEach(v => Array.prototype.push.apply(arr2, v.split(',')));

console.log(arr2);
漂亮男人
var a = [];
var oldarr = ["0", "1", "2", "3,4,5,6", "7,8", "9,10"];
oldarr.forEach(function(val){
    a = a.concat(val.split(','));
})

// ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
console.log(a);
曾经蜡笔没有小新
let arr = ["0", "1", "2", "3,4,5,6", "7,8", "9,10"];
console.log( arr.join().split(/,|''/) )

https://jsfiddle.net/1yqzea2f/

曾经蜡笔没有小新

Another reference

arr.toString().split(',')
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template