简体   繁体   English

Javascript:将键添加到多个值对象

[英]Javascript: Add Key to an Multiple Object of Values

I have this object that log out as in:我有一个注销的对象,如下所示:

{0: "16407", 1: "16309", 2: "16308", 3: "16307", 4: "16306", 5: "16305", 6: "16303", 7: "16302", 8: "16301", 9: "16300", 10: "16299", 11: "16298", 12: "16297", 13: "16296", 14: "16294", 15: "16293", 16: "16292", 17: "16290", 18: "16285", 19: "16277"}

How can I restructure this to log out as follows:我如何重构它以注销如下:

{"name": "16407" }, {"name": "16309"}, {"name": "16308"}....

You could move the values into an array and map objects.您可以将值移动到数组中并映射对象。

 var object = { 0: "16407", 1: "16309", 2: "16308", 3: "16307", 4: "16306", 5: "16305", 6: "16303", 7: "16302", 8: "16301", 9: "16300", 10: "16299", 11: "16298", 12: "16297", 13: "16296", 14: "16294", 15: "16293", 16: "16292", 17: "16290", 18: "16285", 19: "16277" }, result = Object.assign([], object).map(name => ({ name })); console.log(result);

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

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