My function looks like this:
function ross(array) {
return array.map(function(data) {
return data.reduce(function(obj, item) {
obj[item[0]] = item[1];
return obj;
}, {});
});
}
ross(array);
This code is responsible for converting a 3-dimensional array into an array of objects. The part I am particularly interested in is as follows:
return data.reduce(function(obj, item) {
obj[item[0]] = item[1];
return obj;
}, {});
In the return obj
line, there is another set of brackets after the comma (,). I have tried changing it to square brackets []
, which resulted in the output being transformed into a two-dimensional array.
I am curious if anyone can clarify what purpose the extra bracket serves?