cachaito
4/26/2019 - 8:40 AM

Loops for...in and for...of

// Iterates for all properties through chain
for (const i in data) {
  if (data.hasOwnProperty(data[i])) {
    const item = data[i];
  }
}

// ES6
for (const i of data) {
  const item = i;
}

// Little trick with destructing. Instead of:
for (const periods of PERIODS_SET) {
  const [from, to] = periods;
}

// We can do:
for (const [from, to] of PERIODS_SET) {
 ...
}