I can\'t find a similar question and I\'m a bit stuck. I have the following JSON array:
[
{
\"Name\": \"element1\",
\"Attributes\": [\"1\
You have answers to choose from. Just for fun: this one uses es6
"use strict";
let uniqueAttr = [];
const obj = [
{
"Name": "element1",
"Attributes": ["1", "2"]
},
{
"Name": "element2",
"Attributes": ["1","3" ]
},
{
"Name": "element3",
"Attributes": []
}
];
obj.forEach( element =>
element.Attributes.forEach(
attr => uniqueAttr.indexOf(attr) < 0 && uniqueAttr.push(attr)
)
);
document.querySelector("#result").textContent = uniqueAttr;