我想使用javascript解析此字符串,如何执行此操作
[ +919999999999, +919999999999].
我想将输出显示为+919999999999
和+919999999999
答案 0 :(得分:1)
var str = "[ +919999999999, +919999999999]";
var val = str.replace('[','').replace(']','').split(',');
alert(val[0]); //+919999999999
答案 1 :(得分:0)
如果是字符串,请使用替换来替换[]
并将其拆分......
var data= "[ +919999999999, +919999999999]".
var generatedValue = data.replace('[','').replace(']','').split(',');
alert(generatedValue[0]); //alerts +919999999999
alert(generatedValue[1]); //alerts +919999999999
如果是数组(看起来像......),请使用[index]
来获取它
试试这个
var data= "[ +919999999999, +919999999999]".
alert(data[0]); //alerts +919999999999
alert(data[1]); //alerts +919999999999