Converting JavaScript object with numeric keys into array

前端 未结 16 2436
-上瘾入骨i
-上瘾入骨i 2020-11-22 03:09

I have an object like this coming back as a JSON response from the server:

{\"0\":\"1\",\"1\":\"2\",\"2\":\"3\",\"3\":\"4\"}

I want to conv

16条回答
  •  [愿得一人]
    2020-11-22 03:39

    There is nothing like a "JSON object" - JSON is a serialization notation.

    If you want to transform your javascript object to a javascript array, either you write your own loop [which would not be that complex!], or you rely on underscore.js _.toArray() method:

    var obj = {"0":"1","1":"2","2":"3","3":"4"};
    var yourArray = _(obj).toArray();
    

提交回复
热议问题