How to convert the array as shown into:
["0","1","2","3","4","5","6","7","8","9","10"]
天蓬老师2017-06-14 10:56:01
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.
代言2017-06-14 10:56:01
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);
漂亮男人2017-06-14 10:56:01
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);
曾经蜡笔没有小新2017-06-14 10:56:01
let arr = ["0", "1", "2", "3,4,5,6", "7,8", "9,10"];
console.log( arr.join().split(/,|''/) )
https://jsfiddle.net/1yqzea2f/