Iterate over JavaScript object with index

This is just meant to be an addition to jonas w’s solutions. If you need the key of the current value: const object = {a:2, b:4, c:6, d:8}; for (const [index, [key, value]] of Object.entries(Object.entries(object))) { console.log(`${index}: ${key} = ${value}`); } Object.entries(object).forEach(([key, value], index) => { console.log(`${index}: ${key} = ${value}`); }); Of course, you can … Read more

constructor vs componentWillMount; what a componentWillMount can do that a constructor cannot?

Does this means, inside componentWillMount, if we call setState in an async method’s callback (can be a promise callback), React blocks initial rendering until the callback is executed? No, see here. The following code doesn’t block render (bear in mind this would be an anti pattern anyways to call setState there) componentWillMount: function() { new … Read more