简体   繁体   English

使用对象的属性作为键将对象添加到散列/数组

[英]Adding object to hash/array using a object's property as a key

var generated_Obj= {
              id: 'unqiue',
              ....
              some other properties
            }

            var hash = {};

I would be grateful to know how to add generated_Obj to hash using generated_Obj.id as a key. 我很高兴知道如何使用generated_Obj.id作为键将generated_Obj添加到哈希。

If a solution with push() method is possible I would like to learn about it either, ofcourse if there's approach that is efficent it's better 如果使用push()方法的解决方案是可能的,我也想了解它,当然,如果有方法是有效的,那么它更好

10x for your kind help :) 10x为您的帮助:)

您可以使用[]运算符将对象添加到对象(您称为哈希):

hash[generatedObject.id] = generatedObject;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM