ES7+ Object.values (iterate through literal objects)

JS
S
JavaScript

Iterate through literal objects as if we were iterating over an array. https://github.com/tc39/ecma262/releases *New Feature: ES2017 Draft 2016-07-25

1// Iterate over literal objects with object.values
2const messageBrokers = {
3  "low_load": [
4    {
5      id: 1,
6      name: "rmq1"
7    },
8    {
9      id: 2,
10      name: "rmq2"
11    },
12    {
13      id: 3,
14      name: "rmq3"
15    },
16  ],
17  "high_loader": [
18    {
19      id: 4,
20      name: "rmq4"
21    },
22    {
23      id: 5,
24      name: "rmq5"
25    }
26  ]
27};
28
29Object.values(messageBrokers).forEach((loadGroup) => {
30  loadGroup.forEach((broker) => {
31    console.log(broker.name, "(ID: " + broker.id + ")");
32  });
33});
34

Created on 6/14/2017