Onyooo Onyooo - 3 years ago 129
Javascript Question

Javascript's for..of with curly brackets

Looking through Atom's source code, I found this use of the


for (const {name, duration, x} of results) {
dataByBenchmarkName[name] = dataByBenchmarkName[name] || {points: []}
dataByBenchmarkName[name].points.push({x, y: duration})

I 'm trying to replicate this iteration in the terminal, but the block never executes (as if I'm missing a bracket). I've tried iterating over objects (shallow, and deep), and arrays. When I take the curly brackets out, the statement works as documented. Can anyone give me a working example with brackets to learn from? Something simple like:

var test = ...;
for(var {x,y,z} of test) {


Answer Source

This works

var test = [{x:1,y:3,z:2},{x:5,y:6,z:3}]
for(var {x,y,z} of test) {

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download