TheNiceGuy
TheNiceGuy

Reputation: 3730

Append data to JSON element

I have some JSON data. For example:

["Test1","Internet Explorer 4.0","Win 95+","4","X","X"],
["Test2","Internet Explorer 4.0","Win 95+","4","X","Y"]

What i want is to add another "value" to each of this elements. For example:

["Test1","Internet Explorer 4.0","Win 95+","4","X","X", "NEW1"],
["Test2","Internet Explorer 4.0","Win 95+","4","X","Y", "NEW2"]

I tried many things but can't get it to work properly.

apend() adds a completely new element therefore that is not working.

What is the correct way to do this?

Upvotes: 0

Views: 63

Answers (1)

alexmac
alexmac

Reputation: 19607

Use Arry.push function to add a new element:

var data = [["Test1","Internet Explorer 4.0","Win 95+","4","X","X"],
            ["Test2","Internet Explorer 4.0","Win 95+","4","X","Y"]];
for (var i = 0; i < data.length; i++) {
   data[i].push('NEW' + (i + 1));
}

Upvotes: 1

Related Questions