且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Javascript中将索引关联数组的数组转换为逗号分隔的关联数组

更新时间:2022-06-21 23:56:04

您可以使用

You could use Object.assign with an array as target object.

var data = { 0: { abc: 123, xyz: 456, foo: null, bar: 0 }, 1: { abc: 235, xyz: 556, foo: null, bar: 0 } },
    array = Object.assign([], data);

console.log(array);

或者只是 Object.值 (如果索引无关紧要).

Or just Object.values if the index does not matter.

var data = { 0: { abc: 123, xyz: 456, foo: null, bar: 0 }, 1: { abc: 235, xyz: 556, foo: null, bar: 0 } },
    array = Object.values(data);

console.log(array);