I need to go through multiple arrays and create one new array with all the values from the multiple arrays without duplicate, is there any plugins/quick way I can do this?
var x = {
"12": [3, 4],
"13": [3],
"14": [1, 4]
};
The result should look something like this:
[1,3,4];
You can do this using ES6 spread syntax and Object.values
method.
var x = {
"12": [3, 4],
"13": [3],
"14": [1, 4]
}
const result = [...new Set([].concat(...Object.values(x)))]
console.log(result)
Solution using Lodash
var x = {
"12": [3, 4],
"13": [3],
"14": [1, 4]
}
const result = _.uniq(_.flatten(_.values(x)))
console.log(result)
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
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