console.log(this.item_images)
console.log(JSON.parse("["+this.item_images+"]"))
我想将 this.item_images 转换为数组并循环遍历它,为什么我无法解析它?以下是上述代码在控制台中的结果。注意:我 console.log(typeof this.item_images)
它是一个字符串。
最佳答案
this.item_images
似乎是一个只有一个元素的数组:字符串 '038...6aa'
所以我猜你可能想将字符串分割到另一个数组中。
var arr = this.item_images[0].split(',');
然后就可以循环数组arr
了。
更新:如果 this.item_images
是字符串,请使用:
var arr = this.item_images.split(',');
相反。
关于javascript - JSON.parse 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31872979/