Sololearn: Learn to Code
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grátis
+ 1
The = operator is used for assignment within the reduce() function to build an object where the id properties of the objects in the array become keys, and the corresponding name properties become values.
5th May 2024, 8:54 PM
`нттየ⁴⁰⁶
`нттየ⁴⁰⁶ - avatar
+ 1
Dec Fathani The = operator is indeed used, but not in the context of assigning item.name to item.id. Instead, it's used to assign item.name to a property of an object (obj) using item.id as the key. See the snippet, obj[item.id] = item.name; Here, item.name is assigned to obj[item.id], the line obj[item.id] = item.name;, item.id is used as the key to assign the value of item.name to the property of the obj object. So, item.id is not being reassigned to item.name. Instead, item.id is being used as a key to create a property in the obj object, and the value of item.name is assigned to that property. That's why item.id still exists in the output. It's being used as the key in the resulting object, and its corresponding value is the name property of each object in the original array.
5th May 2024, 9:16 PM
`нттየ⁴⁰⁶
`нттየ⁴⁰⁶ - avatar
+ 1
You're welcome Dec Fathani
5th May 2024, 10:37 PM
`нттየ⁴⁰⁶
`нттየ⁴⁰⁶ - avatar