# Arrays stored in data storage

**URL:** <https://forum.code.org/t/arrays-stored-in-data-storage/25502>\
**Category:** CS Principles\
**Tags:** csp-unit-5\
**Created:** [March 12, 2019, 5:04pm UTC](https://forum.code.org/t/arrays-stored-in-data-storage/25502 "2019-03-12T17:04:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zsawyer](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/zsawyer/32/4302_2.png) [@zsawyer](https://forum.code.org/u/zsawyer)\
**Post date:** [March 12, 2019, 5:04pm UTC](https://forum.code.org/t/arrays-stored-in-data-storage/25502/1 "2019-03-12T17:04:31Z")

</div>

I know that I can store an array in [code.org](http://code.org)’s data storage, but can readRecords pull an array out of a column?

---

<div class="post-metadata">

**Author:** ![josh](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/josh/32/868_2.png) [@josh](https://forum.code.org/u/josh)\
**Post date:** [March 12, 2019, 5:25pm UTC](https://forum.code.org/t/arrays-stored-in-data-storage/25502/2 "2019-03-12T17:25:29Z")

</div>

If you want to record and retrieve arrays in the data backend you’ll need to encode it as JSON. So when recording, use `JSON.stringify(my_array)` and then when retrieving you can decode that JSON string with `JSON.parse(my_array)`. Here’s a quick example that that stores an array to a key/value pair and then immediately retrieves it [https://studio.code.org/projects/applab/3uEp0OBgJkzqRYdfrK5Dag/view](https://studio.code.org/projects/applab/3uEp0OBgJkzqRYdfrK5Dag/view)

---

<div class="post-metadata">

**Author:** ![zsawyer](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/zsawyer/32/4302_2.png) [@zsawyer](https://forum.code.org/u/zsawyer)\
**Post date:** [March 14, 2019, 3:10pm UTC](https://forum.code.org/t/arrays-stored-in-data-storage/25502/3 "2019-03-14T15:10:44Z")

</div>

Thank you, that was a perfect solution.  
The same process can for more complicated objects as well.  
var assn1 = new ASSIGNMENT(“Work”, {“val”:80,“weight”:0.2});  
var assnCopy;  
function ASSIGNMENT (name, grade){  
this.name = name;  
this.grade = grade;  
}

```
createRecord("mytable", {data:JSON.stringify(assn1)}, function() {});
readRecords("mytable", {}, function(records) {
  console.log(records[2].data.name);//undefined
  console.log(records[2].data); //{"name":"Work","grade":{"val":80,"weight":0.2}}
  assnCopy = JSON.parse(records[2].data);
  console.log(assnCopy);//{"name":"Work","grade":{"val":80,"weight":0.2}}
  console.log(assnCopy.grade.val);//80
});
```
