view raw
Kalashri Aundhkar Kalashri Aundhkar - 6 months ago 44
Javascript Question

How to make union of nested array in lodash

I have below array format and i want to make union of it using lodash or normal js.

var testArray = [[1,2,3,4,5,6,7,8],[1,2,3,4,5,10,7,8],[1,2,3,6,7,8],[9],[3,4,5]]

I want to make union of all these into one and output should be below array.

testArray = [1,2,3,4,5,6,7,8,9,10]


You could combine flattenDeep with _.union. If needed apply sorting

var testArray = [[1,2,3,4,5,6,7,8],[1,2,3,4,5,10,7,8],[1,2,3,6,7,8],[9],[3,4,5]],
    result = _.chain(testArray)

<script src=""></script>