I have an array:
const arr = [ 'name=Jon', 'weapon=sword', 'hair=shaggy' ]
And I want to convert it to an object like this:
const obj = { name: 'Jon', weapon: 'sword', hair: 'shaggy' }
I've tried splitting the array by the = to get the key and value and then mapping the new array and sending those values to an empty object but it doesn't get the right key
const split = arr.map( el => el.split('=') )
let obj = {};
split.map( el => {
const key = el[0];
const val = el[1];
obj.key = val;
}
)
obj returns as {key: 'shaggy'}