To use for...of
loop you should define an appropriate iterator for your object using [Symbol.iterator]
key.
Here is one possible implementation:
let options = {
male: 'John',
female: 'Gina',
rel: 'Love',
[Symbol.iterator]: function * () {
for (let key in this) {
yield [key, this[key]] // yield [key, value] pair
}
}
}
Though, in most cases it'll be better to iterate over objects using plain for...in
loop instead.
Alternatively you could convert your object to iterable array using Object.keys
, Object.values
or Object.entries
(ES7).