var str = "A-2-12"; var str1 = str.split('-'); console.log(str1); var arr = str1.reverse().reduce((pre,cur,i) => { if(i==0) { pre.push(cur) return pre } return [cur,pre] },[]) console.log(arr) // ["A"["B",["C"]]]
var str = "A-2-12"; var str1 = str.split('-'); console.log(str1); var arr = str1.reverse().reduce((pre,cur,i) => { if(i==0) { pre.push(cur) return pre } return [cur,pre] },[]) console.log(arr) // ["A"["B",["C"]]]