# Arrays in items.add?

**URL:** https://forums.fusetools.com/t/arrays-in-items-add/1870
**Category:** How-to Discussions
**Created:** [August 2, 2017, 4:40pm UTC](https://forums.fusetools.com/t/arrays-in-items-add/1870 "2017-08-02T16:40:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![znoopykid](https://avatars.discourse-cdn.com/v4/letter/z/dbc845/32.png) [@znoopykid](https://forums.fusetools.com/u/znoopykid)
#### Post date: [August 2, 2017, 4:40pm UTC](https://forums.fusetools.com/t/arrays-in-items-add/1870/1 "2017-08-02T16:40:04Z")

</div>

Is it possible to add arrays within an items.add loop? Eg something along the lines of:

JS

```auto
for(var i=0,len=data.val.length;i<len;i++){
items.add({
id:data.val[i].id,
oranges[0]:data.val[i].orange1,
oranges[1]:data.val[i].orange2,
oranges[2]:data.val[i].orange3,
})
}

```

.UX

```auto
<Each Items="{items}">
<Each Items="{oranges}">
<Text Value="{oranges[1]}" />

```

---

<div class="post-metadata">

### Author: ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)
#### Post date: [August 2, 2017, 4:51pm UTC](https://forums.fusetools.com/t/arrays-in-items-add/1870/2 "2017-08-02T16:51:14Z")

</div>

Yes, adding arrays within objects is generally okay, although the syntax is different from what you’re showing here.

```auto
{oranges: ["one", "two", "three"]}

```

Exactly how you craft that object and nested arrays is totally up to you, and it’s a JavaScript thing.

What’s the real question though? Could you post a complete, minimal example of what you’ve tried to do and what didn’t work?

---

<div class="post-metadata">

### Author: ![znoopykid](https://avatars.discourse-cdn.com/v4/letter/z/dbc845/32.png) [@znoopykid](https://forums.fusetools.com/u/znoopykid)
#### Post date: [August 2, 2017, 6:26pm UTC](https://forums.fusetools.com/t/arrays-in-items-add/1870/3 "2017-08-02T18:26:12Z")

</div>

Thanks.

Still learning and sandboxing. Basically trying to understand best ways of using each when importing json files, but got stuck when trying to figure out how to deal with arrays, so for above example modified:

```auto
for(var i=0,len=data.val.length;i<len;i++){
items.add({
id:data.val[i].id,
oranges:[data.val[i].orange1,data.val[i].orange2,data.val[i].orange3]
})
}

```

Then iterating the items and within items iterate its arrays:

```auto
<Each Items="{items}">
<Text Value="{id}" />
<Each Items="{oranges}"> ???
<Text Value="{oranges[1]}" /> ???
</Each>
</Each>

```

Clearly the ??? lines is a wrong approach.

---

<div class="post-metadata">

### Author: ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)
#### Post date: [August 2, 2017, 9:36pm UTC](https://forums.fusetools.com/t/arrays-in-items-add/1870/4 "2017-08-02T21:36:30Z")

</div>

I still don’t see the complete example, and I don’t really see any specific question either. Here you go then, this is what a bucket with 3 boxes and a variable amount of fruits inside them looks like in Fuse, using vanilla JS objects and arrays:

```auto
<App>
	<JavaScript>
		var types = [
			{title: "orange", count: 4},
			{title: "apple", count: 3},
			{title: "pear", count: 5}
		];

		var bucket = [];
		types.forEach(function(t) {
			var box = {type: t.title + "s", fruits: []};
			for (var i = 0; i < t.count; i++) {
				box.fruits.push(t.title + " " + (i + 1));
			}
			bucket.push(box);
		});

		module.exports = {
			bucket: bucket
		};
	</JavaScript>
	<StackPanel Margin="4" ItemSpacing="4">
		<Each Items="{bucket}">
			<StackPanel ItemSpacing="2">
				<Text Value="{type}" Background="#ccc" />
				<Each Items="{fruits}">
					<Text Value="{}" />
				</Each>
			</StackPanel>
		</Each>
	</StackPanel>
</App>

```
