i have the following array
let arr = [
[
"[email protected]",
"[email protected]"
],
[
"[email protected]",
"[email protected]"
]
]
i want get the unique values from this array. so im expecting my result to be like this
[
[
"[email protected]",
"[email protected]",
"[email protected]"
]
]
i have used array unique function but not able to get the result
var new_array = arr[0].concat(arr[1]);
var uniques = new_array.unique();
this worked if i have two index but how about for multiple index?
You can use .flat()
to flatten your array and then use Set
to get its unique values.
Demo:
let arr = [
[
"[email protected]",
"[email protected]"
],
[
"[email protected]",
"[email protected]"
]
]
let arr2 = [...new Set(arr.flat(1))];
console.log(arr2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With