Question: Based on the inputArray i want to create outputArray, **marks** calculations in outputArray is like below

Group 1 = Physics + Chemistry + Maths

Group 2 = History + Geography

Group 3 = Language First + Language Second

Group Total = Group 1 + Group 2 + Group 3

```
var inputArray = [
  { subject: 'Physics', marks: '60' },
  { subject: 'History', marks: '35' },
  { subject: 'Chemistry', marks: '50' }, 
  { subject: 'Language First', marks: '70' },
  { subject: 'Geography', marks: '65' },
  { subject: 'Maths', marks: '40' },
  { subject: 'Language Second', marks: '50' },
  .
  .
  .
];

var outputArray = [
  { subject: 'Group 1', marks: '150' },
  { subject: 'Group 2', marks: '100' },
  { subject: 'Group 3', marks: '120' },
  { subject: 'Group Total', marks: '370' },
  .
  .
  .
];

```

Answer: 
You can still save it as a string but the serialization should be something like [JSON](http://www.w3schools.com/js/js_json.asp).

To convert to json (encode) use [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). This returns a string that you can save to the file:

```
var json_string = JSON.stringify(my_array); 

```

Afterwards, to decode the string in the file (after reading it) use [JSON.parse](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)

```
var my_array = JSON.parse(json_string);

```
You can use `JSON.stringify` to convert a multi-level array to a string. And then you can use `JSON.parse` to convert it back to an array. Once you have the string you can save and restore it and use these methods to re-create the array.

```
a = [1, 2, [3, 4, [5, 6, [7, 8], 9]]]
> [1, 2, Array[3]]

s = JSON.stringify(a)
> "[1,2,[3,4,[5,6,[7,8],9]]]"

a2 = JSON.parse(s)
> [1, 2, Array[3]]

```