I have this question List out all the unique values of attribute “z” found in the following array list:
and the input is
var x = ["<r><a z=\"4\"><a z=\"2\"></r>"]
I tried solve it with following code
let x = ["<r><a z=\"4\"><a z=\"2\"></r>"];
let unique = [];
let temp = [];
let pattern = /[0-9]/g;
x.filter((item, i) => {
temp = item.match(/\d+/g).map(Number);
});
The output should be unique numbers instead i.e. 1,2,3,4
but it gives a long array of random numbers between 1-4. How to fix this?