Convert array to JSON

后端 未结 9 1683
南笙
南笙 2020-11-22 04:28

I have an Array var cars = [2,3,..] which holds a few integers. I\'ve added a few values to the array, but I now need to send this array to a page via jQuery\'s

9条回答
  •  我寻月下人不归
    2020-11-22 04:48

    Wow, seems it got a lot easier nowadays... 3 ways you can do it:

    json = { ...array };
    
    json = Object.assign({}, array);
    
    json = array.reduce((json, value, key) => { json[key] = value; return json; }, {});
    

提交回复
热议问题