如何在Javascript中将索引关联数组的数组转换为逗号分隔的关联数组 [英] How to convert Array of Indexed Associative Array to Comma Separated Associative Array in Javascript

查看:90
本文介绍了如何在Javascript中将索引关联数组的数组转换为逗号分隔的关联数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似索引的关联数组

I have an indexed Associative Array like

[
0:{abc: 123, xyz: 456, foo: null, bar: 0}
1:{abc: 235, xyz: 556, foo: null, bar: 0}
]

现在如何将其转换为逗号分隔的形式

now how to convert it to comma separated form

[{abc: 123, xyz: 456, foo: null, bar: 0},{abc: 235, xyz: 556, foo: null, bar: 0}
    ]

推荐答案

您可以使用

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);

这篇关于如何在Javascript中将索引关联数组的数组转换为逗号分隔的关联数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆