合并属性上的javascript对象 [英] Merging javascript objects on property

查看:87
本文介绍了合并属性上的javascript对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所拥有的是一个具有三个成员的对象. 这些成员中的每个成员都有一个对象数组,每个对象都有新成员. 因此,访问内部"成员将像这样完成.

What I have is an object with three members. Each of these members has an array of objects each with new members. So accessing an "inner" member would be done like this.

outerObject.outerObjectMember[innerObjectPlacementInArray].innerObjectMember;

在三个外部成员的每个成员中,数组中都有一个内部对象,其值(id)等于其他两个外部成员内部对象成员的值. 任何一个外部成员中都没有重复的ID. 我想做的是创建通过将所有内部对象连接到(id)值上而创建的对象,这些对象具有与每个内部成员的属性相同的ID.

In each of the three outer members there's an inner object in the array with a value (id) that is equal to a value in both of the other outer members inner objects members. There are no duplicate ids in either outer member. What I want to do is create objects that are made by joining all the inner objects on the (id) value resulting in objects that have the properties of each inner member with the same id.

最后,这些对象应位于数组中.

Finally these objects should be in an array.

我知道可以使用很多循环和ifs来完成此操作,但是我想知道是否存在任何方法,或者有人是否有一个不错的,快速的(针对性能的解决方案)

I know it can probably be done using a lot of loops and ifs but I was wondering if any method existed or if someone had a nice and quick(perfomance-wise) solution

这有意义还是需要进一步澄清?

Does this make sense or does it need further clarification ?

推荐答案

因此您要更改此设置:

var outer = {
    om1 = [
        im1_1, common_id, im1_3...
    ],
    om2 = [
        im2_1, im2_2, common_id...
    ],
    om3 = [
        common_id, im3_2, im3_3...
    ]
}

变成...到底是什么?

into... what exactly?

我知道这不太正确,但我正在观看奥运会和我要去睡觉了也许这可以帮助您为他人澄清.

I know this isn't quite right, but I'm watching the Olympics & I need to go to bed. Maybe this can help you clarify for others.

无论如何,您需要使用一两个循环:)

Anyway, you need to use a loop or two :)

这篇关于合并属性上的javascript对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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