ecmascript 6 - Is it possible to use ES6 For..Of on an Object instead of an Array? -


this question has answer here:

on babel-node repl

typeerror: undefined not function

when trying iterate using for..of on object. don't why for..in work, for..of won't. arrays?

const config = { base: 'iei', url: 'www.' }  (let of config) { console.log(i); } 

no, for of iterables. not objects iterable. can create custom iterator object, though:

object.values = function* (o) {     (let k of object.keys(o))         yield o[k]; };  (let of object.values(config)) console.log(i); // 'iei', 'www.' 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -