JavaScript
for...of vs. map

by Benny Neugebauer

const yaml = require('js-yaml');
const fs = require('fs');

const parsedYaml = yaml.safeLoad(fs.readFileSync('domains.yml', 'utf8'));

const cnames = [];
for (config of parsedYaml.cnames.create) {
  cnames.push(config.cname);
}

console.log(cnames.length);

const yaml = require('js-yaml');
const fs = require('fs');

const parsedYaml = yaml.safeLoad(fs.readFileSync('domains.yml', 'utf8'));

const cnames = parsedYaml.cnames.create.map(config => config.cname);

console.log(cnames.length);