I got this from MDN array.map page under the examples. They are using square brackets to set the key inside of the object that the function is returning like so:
const kvArray = [
{ key: 1, value: 10 },
{ key: 2, value: 20 },
{ key: 3, value: 30 },
];
const reformattedArray = kvArray.map(({ key, value}) => ({ [key]: value }));
console.log(reformattedArray)
Without the square brackets around the key variable inside of the reformattedArray function, it just returns "key" as each key/value pairs' key. And, it seems weird to me that it is'nt read as the variables value, but as "key".
Why does the word key (without square brackets) make it read as "key"? And, why does the square brackets make it read the key value of the passsed in object?