How would I take an array that console.logs as this:
[Kzljszzz15OFcln1XGM, {make: "John Deere ", model: "5055", uid: "Kzljszzz15OFcln1XGM", year: "1953"}]
and turn it into this plain object? :
{Kzljszzz15OFcln1XGM: {make: "John Deere ", model: "5055", uid: "Kzljszzz15OFcln1XGM", year: "1953"}
where it's a key value pair where the value is more key value pairs?
So far I've tried:
const myArray = //the array mentioned above
function toObject(arr) {
const rv = {};
for (let i = 0; i < arr.length; ++i) {
rv[i] = arr[i];
return rv;
}
console.log(toObject(myArray));
And also:
Object.assign({}, myArray);
These won't even convert myArray into a plain object, let alone the format I'm after for some reason.
I've set after this problem in a couple of totally wrong directions because I was logging from the wrong places in my code. But now I'm sure I'm asking the right question. Any help would be appreciated!