# Get list of all children

**URL:** <https://discourse.threejs.org/t/get-list-of-all-children/18891>\
**Category:** Questions\
**Tags:** models\
**Created:** [September 21, 2020, 1:15pm UTC](https://discourse.threejs.org/t/get-list-of-all-children/18891 "2020-09-21T13:15:01Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Khalido](https://avatars.discourse-cdn.com/v4/letter/k/dec6dc/32.png) [@Khalido](https://discourse.threejs.org/u/Khalido)\
**Post date:** [September 21, 2020, 1:15pm UTC](https://discourse.threejs.org/t/get-list-of-all-children/18891/1 "2020-09-21T13:15:01Z")

</div>

Hi, I am trying to get a list off all children from my model like in the picture

 ![example](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/2X/d/ddef831c35401d0c04b8532bf6f94727dd578f05.jpeg)  
Here is my JS file[app.js](https://discourse.threejs.org/uploads/short-url/uuaMLr7mf9cMq1eEmVmlwCT09R0.js) (2.8 KB) .  
Thanks for helping out.

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [September 21, 2020, 1:21pm UTC](https://discourse.threejs.org/t/get-list-of-all-children/18891/2 "2020-09-21T13:21:59Z")

</div>

When adding the loaded model to the scene, you can use the following code in order to traverse through the object hierarchy and push all descendants into an array:

```javascript
const objects = [];

// in your onLoad() callback

model.traverse( ( child ) => {

    if ( child.isMesh ) objects.push( child );

} );

```

Change the `if` condition if you also want to add lines or point clouds.

---

<div class="post-metadata">

**Author:** ![Khalido](https://avatars.discourse-cdn.com/v4/letter/k/dec6dc/32.png) [@Khalido](https://discourse.threejs.org/u/Khalido)\
**Post date:** [September 22, 2020, 8:22am UTC](https://discourse.threejs.org/t/get-list-of-all-children/18891/3 "2020-09-22T08:22:16Z")

</div>

> [@Mugen87](#):
>
> ```javascript
> model.traverse( ( child ) {
> 
> if ( child.isMesh ) objects.push( child );
> 
> } );
> 
> ```

Hi When i add your code i get an error like this

> Uncaught SyntaxError: missing ) after argument list

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [September 22, 2020, 8:29am UTC](https://discourse.threejs.org/t/get-list-of-all-children/18891/4 "2020-09-22T08:29:08Z")

</div>

Ups, I had a typo in the arrow function. I’ve updated my post.

---

<div class="post-metadata">

**Author:** ![Khalido](https://avatars.discourse-cdn.com/v4/letter/k/dec6dc/32.png) [@Khalido](https://discourse.threejs.org/u/Khalido)\
**Post date:** [September 24, 2020, 7:58am UTC](https://discourse.threejs.org/t/get-list-of-all-children/18891/5 "2020-09-24T07:58:17Z")

</div>

Is there a way to get only the 3D elements and toggle them on and off like a layer. Thanks for helping out. I’m a student so I new to this kind off stuff

---

<div class="post-metadata">

**Author:** ![Khalido](https://avatars.discourse-cdn.com/v4/letter/k/dec6dc/32.png) [@Khalido](https://discourse.threejs.org/u/Khalido)\
**Post date:** [September 24, 2020, 8:07am UTC](https://discourse.threejs.org/t/get-list-of-all-children/18891/7 "2020-09-24T08:07:44Z")

</div>

> [@Mugen87](#):
>
> Change the `if` condition if you also want to add lines or point clouds.

What do you mean with lines or point clouds. Could you explain this to me.

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [September 24, 2020, 9:00am UTC](https://discourse.threejs.org/t/get-list-of-all-children/18891/8 "2020-09-24T09:00:27Z")

</div>

> [@Khalido](#):
>
> What do you mean with lines and point clouds. Could you explain this to me.

You could have [line](https://threejs.org/docs/index.html#api/en/objects/Line) or [point cloud](https://threejs.org/docs/index.html#api/en/objects/Points) objects in your scene graph. If you want to collect all those objects, the code would look like so:

```js
model.traverse( ( child ) {

    if ( child.isMesh || child.isPoints || child.isLine ) objects.push( child );

} );

```

---

<div class="post-metadata">

**Author:** ![Khalido](https://avatars.discourse-cdn.com/v4/letter/k/dec6dc/32.png) [@Khalido](https://discourse.threejs.org/u/Khalido)\
**Post date:** [September 24, 2020, 9:11am UTC](https://discourse.threejs.org/t/get-list-of-all-children/18891/9 "2020-09-24T09:11:49Z")

</div>

ah oke thanks!.  
Is there a way to dispays this array (children) in a dat.gui that can be toggled on and off.

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [September 24, 2020, 9:13am UTC](https://discourse.threejs.org/t/get-list-of-all-children/18891/10 "2020-09-24T09:13:07Z")

</div>

Yes, but I don’t have to code for this ready. I guess you have to figure this out by yourself^^.

---

<div class="post-metadata">

**Author:** ![jrlazz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/jrlazz/32/64383_2.png) [@jrlazz](https://discourse.threejs.org/u/jrlazz)\
**Post date:** [December 8, 2024, 2:30am UTC](https://discourse.threejs.org/t/get-list-of-all-children/18891/11 "2024-12-08T02:30:04Z")

</div>

Hi @Khalido and @Mugen87 …

I always had difficulty finding all the childs meshes… I think this link made me happy. 😉

> **[ismesh.html](https://jrlazz.github.io/anim/ismesh.html)**
