# Array in ValueTree

**URL:** <https://forum.juce.com/t/array-in-valuetree/13634>\
**Category:** General JUCE discussion\
**Created:** [September 26, 2014, 9:24pm UTC](https://forum.juce.com/t/array-in-valuetree/13634 "2014-09-26T21:24:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikolaiaudios](https://avatars.discourse-cdn.com/v4/letter/n/77aa72/32.png) [@nikolaiaudios](https://forum.juce.com/u/nikolaiaudios)\
**Post date:** [September 26, 2014, 9:24pm UTC](https://forum.juce.com/t/array-in-valuetree/13634/1 "2014-09-26T21:24:51Z")

</div>

I'm using the ValueTree as the base for storing application data to disk.

So I got this Array\<int\> that I want to store. what is the best way to put the array inside the ValueTree?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [September 27, 2014, 7:29am UTC](https://forum.juce.com/t/array-in-valuetree/13634/2 "2014-09-27T07:29:00Z")

</div>

You could add each int&nbsp;as a child ValueTree, or turn it into an Array\<var\> and store that in a var, which you can then store in a ValueTree.

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [September 27, 2014, 12:26pm UTC](https://forum.juce.com/t/array-in-valuetree/13634/3 "2014-09-27T12:26:43Z")

</div>

You can trivially create an array like container that operates with the ValueTree for storage. &nbsp;It's probably not as fast if you're in really time critical situation, but mighty convenient.

something like (untested):&nbsp;

```
template <class ObjectType>

class ValueTreeArray {

ValueTreeArray(ValueTree & dataLocation) : tree(dataLocation) {}

ObjectType operator[](int i) const {

return tree.getChild(i)

}

private:

ValueTree tree; 

};
```

And so on until you have all the right container functionality. &nbsp;If you put the right kind of iterator in as well it starts to get pretty useful. &nbsp;I've got one here but it's got a depenency on something a bit too horrible to post :)

The advantage is that you can now have multiple arrays pointing at the same tree, but you can use it just like a normal array.
