0

I have such array in Jquery code:

var marr = new Array();

marr[0] = new Object();
marr[0]["name"] = "Spot 1";
marr[0]["value"] = 20;

marr[1] = new Object();
marr[1]["name"] = "Spot 2";
marr[1]["value"] = 70;

How can I represent this array as a (more or less) user friendly string (to give users an ability to send some values as plugin options). An than parse it back for jquery?

Kotanet
  • 573
  • 1
  • 8
  • 26

3 Answers3

3

You could have generated a JSON string from the marr array. It may had given you what you are looking for.

> console.log(JSON.stringify(marr));
[
    {
        "name": "Spot 1",
        "value": 20
    },
    {
        "name": "Spot 2",
        "value": 70
    }
]
Alexander
  • 23,432
  • 11
  • 63
  • 73
2

Something like this?

var marr = [ {"name": "Spot 1", "value":20}, {"name": "Spot 2", "value":70} ];

This is same as the code you mentioned above.

Wolf
  • 2,150
  • 1
  • 15
  • 11
1

this will be json representation of array

var marr=[
         {"name":"spot 1","value":20}
         {"name":"spot 2","value":70}
         ]
Ankush Jain
  • 1,532
  • 1
  • 15
  • 24