Objects

[codebyte language=javascript]
let activity = ['Surfing', 'floating'];
myObject=Object.fromEntries(activity)
console.log(myObject);
[/codebyte]

Please why is this not working? What am I missing? documentation link

Object.fromEntries(iterable);

…An iterable such as Array or Map or other objects implementing the iterable protocol.

When we see the word, ‘entries’ we think, key-value pairs:

 > Object.fromEntries([['a', 1], ['b', 2]])
<- {a: 1, b: 2}

yes so I was under the impression this will make a pair- surfing the key and floating the value.
it seems I am missing something important here? Must the array have the potential of returning more than one property for it to work?

It needs to be an entry, not a standalone array. That requires a parent iterable. Check the example. An array of key/value pairs (also arrays). The key/value pairs are the entries.

1 Like