【发布时间】:2021-01-19 13:58:50
【问题描述】:
我正在使用getJSON 获取一组数据,如下所示:
var url = 'http://localhost:5000/api/items';
$.getJSON(url, function(response) {
var response2 = []
console.log(response)
});
我的控制台输出如下:
[{"id": 1, "price": 20, "name": "test"}, {"id": 4, "price": 30, "name": "test2"}]
我需要将这些值转换成这种格式的数组:
[[1, 20, "test"], [4, 30, "test2"]]
我尝试了以下代码,但结果不同:
$.each(response, function (key, val) {
response2.push(val)
});
console.log(response2) // output = [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
非常感谢任何帮助!
【问题讨论】: