Convert string array representation back to an array

后端 未结 3 1970
心在旅途
心在旅途 2020-11-27 22:03

I have a string representation of an array:

\'[\"item1\", \"item2\", \"item3\"]\'

I\'m trying to convert this back to an array.

Any

相关标签:
3条回答
  • 2020-11-27 22:47

    You also can Use

    var genericList = eval('(' + s + ')');
    
    for(i=0;i<genericList.lengthl;i++){
       alert("element : " + genericList[i]);
    }
    
    0 讨论(0)
  • 2020-11-27 22:48

    Just use JSON.parse('["item1", "item2", "item3"]');

    0 讨论(0)
  • 2020-11-27 22:59

    Try JSON.parse:

     ary = JSON.parse(s);
    

    Most browsers support it natively, for others you'll need json.js

    0 讨论(0)
提交回复
热议问题