标签:style blog io ar color sp on div log
直接转引号引出的数组为真正数组。如果需要也可以作简单修改以适应对象情况。
var a =‘[34444a44,[a1,[4,5],[2,3]],1]‘ function turn(a){ turn.c = turn.c || 1; var res; var str; while( turn.c < a.length){ res = res || []; if(a[turn.c] === ‘[‘){ turn.c++; res.push(turn(a)) }else if(a[turn.c] === ‘]‘){ return res; }else if(/\w/.test(a[turn.c])){ str = str ? str.concat(a[turn.c] ):a[turn.c] if(/\]|\,/.test(a[turn.c+1])){ if(str - parseFloat( str ) >= 0) str -=0;; res.push(str); str = undefined; } } turn.c++; } return res; } console.log(turn(a)) // Array [ "34444a44", Array[3], 1 ]
标签:style blog io ar color sp on div log
原文地址:http://www.cnblogs.com/winderby/p/4164929.html