I have encountered an issue with a simple block of code:
function toObj(i){
return {
i: i
};
}
numObj=s=>s.map(toObj)
Whenever I provide an array of numbers to numObj, my expectation is for the key and the value to align with the argument that was input. An example of the desired result would be:
numObj([1, 2, 3, 4]) => [{1: 1}, {2: 2}, {3: 3}, {4: 4}]
However, the actual output appears as follows:
numObj([1, 2, 3, 4]) => [{i: 1}, {i: 2}, {i: 3}, {i: 4}]
I am seeking guidance on how to establish the key of the returned object to correspond with the provided argument.