I want to put all attributes in a Html element into an array: like i have a jQuery Object, whichs html looks like this:
Every answer here is missing the simplest solution using the getAttributeNames element method!
It retrieves the names of all the element's current attributes as a regular Array, that you can then reduce to a nice object of keys/values.
const getAllAttributes = el => el
.getAttributeNames()
.reduce((obj, name) => ({
...obj,
[name]: el.getAttribute(name)
}), {})
console.log(getAllAttributes(document.querySelector('div')))