字符串转数组


var a ="['a','b','c']";

转换成

b = ['a','b','c'];

jquery node.js JavaScript

JoJo33 9 years, 4 months ago

 var a ="['a','b','c']";
var result = a.substring(1, a.length - 1).split(',');

人家是鹦鹉酱 answered 9 years, 4 months ago

1、 b = eval(a);
2、如果不想用 eval ,那就手动好了:


 b = a.substring(2, a.length-2).replace(/','/g, ',').split(',');

kong.ws answered 9 years, 4 months ago


 b=eval(a)

FFTADS answered 9 years, 4 months ago


 var b = new Function("return " + a).call();

幕後BOSS answered 9 years, 4 months ago

Your Answer