I used the same names for variables. I don't like messing with global variables very much, so I made a makeData() function, which is a pure function.
makeData()
Then I made a replacement addData() function to have the same functionality as your code. You can use it the same way 😄
addData()
function makeData(arr, uuid = 'id') { const [headings, ...body] = arr; const idPosition = headings.indexOf(uuid); return body.reduce((data, elem) => ({ ...data, ...{ [elem[idPosition]]: Object.fromEntries(elem.map((value, index) => [headings[index], value])) } }), {}); } function addData(arr, uuid = 'id') { Object.assign(data, makeData(arr, uuid)); }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I used the same names for variables. I don't like messing with global variables very much, so I made a
makeData()
function, which is a pure function.Then I made a replacement
addData()
function to have the same functionality as your code. You can use it the same way 😄