例:字符串‘12345’转换成数组[1,2,3,4,5]
let array = '2,5,6,8,4,10,9,15,16,13,3,1,17,11,12'
console.log(array.split(','))//转为数组
//['2', '5', '6', '8', '4', '10', '9', '15', '16', '13', '3', '1', '17', '11', '12']
此时是字符串数组
一步到位 将字符串数字转换成数字数组
let array = '2,5,6,8,4,10,9,15,16,13,3,1,17,11,12'
console.log(array.split(',').map(Number));
//[2, 5, 6, 8, 4, 10, 9, 15, 16, 13, 3, 1, 17, 11, 12]
现在知道map竟然还能这样用!