最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

arrays - Javascript- Convert Dictionary into List of Objects - Stack Overflow

programmeradmin0浏览0评论

I currently have data structued as

{ 
  {id: 
    {prop: value}
  },
  {anotherId: 
    {prop: value}
 }
}

and I want to convert it into an array of objects:

[
   {id: 
     {prop: value}
   },
   {anotherId: 
     {prop: value}
  }
]

How can I acplish this?

I currently have data structued as

{ 
  {id: 
    {prop: value}
  },
  {anotherId: 
    {prop: value}
 }
}

and I want to convert it into an array of objects:

[
   {id: 
     {prop: value}
   },
   {anotherId: 
     {prop: value}
  }
]

How can I acplish this?

Share Improve this question edited Oct 24, 2019 at 18:29 Samuel Rosenstein asked Oct 24, 2019 at 11:54 Samuel RosensteinSamuel Rosenstein 3744 silver badges15 bronze badges 3
  • 2 I'm not sure what that screenshot is trying to municate. Could you edit the question to show exactly what you have, and what exactly you would like it to be instead, including the code that you've tried that doesn't work the way you expect? – Doug Stevenson Commented Oct 24, 2019 at 12:06
  • 1 You don't manipulate data with React--AFAICT there's nothing React or even Firebase about this question--it's just JS. – Dave Newton Commented Oct 24, 2019 at 12:34
  • Thanks for the feedback, see the edited question. The answer that Anthony gave solved my issue. – Samuel Rosenstein Commented Oct 24, 2019 at 18:31
Add a ment  | 

1 Answer 1

Reset to default 9

You could use Object.values()

const obj = {
  a: { 1: 'something', 2: 'something else' },
  b: { 1: 'something', 2: 'something else' }
};

console.log(Object.values(obj));

发布评论

评论列表(0)

  1. 暂无评论