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”]]]
更多内容请见原文,原文转载自:http://www.mark-to-win.com/tutorial/50904.html