I'm trying to get the results back from my loop to be spread into a variable
const updateds = {
...
(Array.from(document.querySelectorAll('.updated')).map(item => {
return {[item.dataset.slug]: item.dataset.position};
}))
};
and the results should be spread to form like so
{"chahan": "1", "jacques-lacoste": "2", "testcover": "3", "kreo": "4"}
but instead i get
{"chahan":"1"},{"jacques-lacoste":"2"},{"testcover":"3"},{"kreo":"4"}
Any idea how to achieve so ?
Using the
map
higher-order method is always going to return an array. If you want to combine the objects of an array into a single object, thereduce
higher-order method is what you want to use.