Question: I have an array of objects that has an array property that I am trying to union together. I have already solved the problem with the code below, which shows what I am trying to do:

```
var dest = [];
_.forEach(parentArray, function (parentItem) {
    _.forEach(parentItem.arrayProperty, function(arrayPropertyItem) {
        dest.push(arrayPropertyItem);
    });
});

```

This works fine. But I am wondering if lodash has any shortcut methods for this. I tried using unionBy/unionWith, but it doesnt seem to have the intended result. Instead simply giving me back the parentArray.

Answer: 
Take a look at [flatMap](https://lodash.com/docs/4.17.4#flatMap) and [flatten](https://lodash.com/docs/4.17.4#flatten). If I understand your data structure (and what you are trying to accomplish) you should be able to do something like this

```
var dest = _.flatMap(parentArray, function(item) {
  return item.arrayProperty;
});

```

If necessary you can use the `_.flatten` on `item.arrayProperty` depending on what you are trying to accomplish. If the `arrayProperty` contains an array of arrays the output will have a nested array as well. If it goes any deeper you may need to use [flattenDeep](https://lodash.com/docs/4.17.4#flattenDeep).

```js
var parentArray = [{item: 'one', children: [1, 2, 3]}, {item: 'two', children: [4, 5, 6]}];

var dest = _.flatMap(parentArray, function(item) {
  return item.children;
});

console.log(dest);
```

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.16.4/lodash.min.js"></script>
```

You can play around with it by having nested arrays in the `children` property and adding `_.flatten` if necessary.
You could use `flatMap` with the *name* of the nested property as second argument:

```
_.flatMap(parentArray, 'arrayProperty')

```

```js
var parentArray = [{
    arrayProperty: [1, 2]
}, {
    arrayProperty: [3, 4]
}];

console.log( _.flatMap(parentArray, 'arrayProperty') );
```

```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.16.4/lodash.min.js"></script>
```