js中有["1","2","3","4"]这样一个string,怎么把它变成array
发布网友
发布时间:2022-05-07 11:55
我来回答
共3个回答
热心网友
时间:2023-10-30 09:22
通过eval()把字符串转换成array.
代码:
<script>
var str = '["1","2","3","4"]';//相关字符串
var arr = eval(str);//通过eval执行字符串,结果arr是一个数组,数组内容是"1","2","3","4"
</script>
补充:
eval() 函数可计算某个字符串,并执行其中的的 JavaScript 代码,并返回通过计算 string 得到的值
热心网友
时间:2023-10-30 09:22
<script>
var temp = '["1","2","3","4"]';
var ary = eval('(' + temp + ')');
for (var i = 0 ;i<ary.length;i++){
alert(ary[i]);
}
</script>
热心网友
时间:2023-10-30 09:23
都把它SET进去!
热心网友
时间:2023-10-30 09:22
通过eval()把字符串转换成array.
代码:
<script>
var str = '["1","2","3","4"]';//相关字符串
var arr = eval(str);//通过eval执行字符串,结果arr是一个数组,数组内容是"1","2","3","4"
</script>
补充:
eval() 函数可计算某个字符串,并执行其中的的 JavaScript 代码,并返回通过计算 string 得到的值
热心网友
时间:2023-10-30 09:22
<script>
var temp = '["1","2","3","4"]';
var ary = eval('(' + temp + ')');
for (var i = 0 ;i<ary.length;i++){
alert(ary[i]);
}
</script>
热心网友
时间:2023-10-30 09:22
通过eval()把字符串转换成array.
代码:
<script>
var str = '["1","2","3","4"]';//相关字符串
var arr = eval(str);//通过eval执行字符串,结果arr是一个数组,数组内容是"1","2","3","4"
</script>
补充:
eval() 函数可计算某个字符串,并执行其中的的 JavaScript 代码,并返回通过计算 string 得到的值
热心网友
时间:2023-10-30 09:23
都把它SET进去!
热心网友
时间:2023-10-30 09:22
<script>
var temp = '["1","2","3","4"]';
var ary = eval('(' + temp + ')');
for (var i = 0 ;i<ary.length;i++){
alert(ary[i]);
}
</script>
热心网友
时间:2023-10-30 09:23
都把它SET进去!
热心网友
时间:2023-10-30 09:22
通过eval()把字符串转换成array.
代码:
<script>
var str = '["1","2","3","4"]';//相关字符串
var arr = eval(str);//通过eval执行字符串,结果arr是一个数组,数组内容是"1","2","3","4"
</script>
补充:
eval() 函数可计算某个字符串,并执行其中的的 JavaScript 代码,并返回通过计算 string 得到的值
热心网友
时间:2023-10-30 09:22
<script>
var temp = '["1","2","3","4"]';
var ary = eval('(' + temp + ')');
for (var i = 0 ;i<ary.length;i++){
alert(ary[i]);
}
</script>
热心网友
时间:2023-10-30 09:23
都把它SET进去!