search

Home  >  Q&A  >  body text

javascript - js A small algorithm question, looking for a better answer.

1. String type"[[1,2],[2,4],[3,6],[1,2]]", hope to get array type[ [1,2],[2,4],[3,6],[1,2]]

怪我咯怪我咯2794 days ago611

reply all(3)I'll reply

  • PHP中文网

    PHP中文网2017-06-30 09:59:28

    var arr = JSON.parse("[[1,2],[2,4],[3,6],[1,2]]");

    reply
    0
  • 漂亮男人

    漂亮男人2017-06-30 09:59:28

    Process ->

    var str =  "[[1,2],[2,4],[3,6],[1,2]]";
    var newStr = JSON.parse(str);
    .log(newStr);

    Packaging ->

    function g(str){
        return JSON.parse(str);
    };

    reply
    0
  • 怪我咯

    怪我咯2017-06-30 09:59:28

    You can just search for JSON.parse. Baidu is better for this kind of problem

    reply
    0
  • Cancelreply