ecmascript 6 - Is it possible to use ES6 For..Of on an Object instead of an Array? -
this question has answer here:
- using objects in of loops 11 answers
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
Post a Comment