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?
asked Jan 19, 2013 at 11:28
Kotanet
5731 gold badge8 silver badges26 bronze badges
-
duplicate? stackoverflow.com/questions/5289403/…mercsen– mercsen2013年01月19日 11:31:46 +00:00Commented Jan 19, 2013 at 11:31
-
or simply dont use an array, use an JSON objectmercsen– mercsen2013年01月19日 11:32:16 +00:00Commented Jan 19, 2013 at 11:32
3 Answers 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
}
]
answered Jan 19, 2013 at 11:53
Alexander
23.5k11 gold badges65 silver badges74 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Something like this?
var marr = [ {"name": "Spot 1", "value":20}, {"name": "Spot 2", "value":70} ];
This is same as the code you mentioned above.
answered Jan 19, 2013 at 11:30
Wolf
2,1351 gold badge15 silver badges11 bronze badges
this will be json representation of array
var marr=[
{"name":"spot 1","value":20}
{"name":"spot 2","value":70}
]
answered Jan 19, 2013 at 11:58
Ankush Jain
1,5271 gold badge15 silver badges24 bronze badges
Comments
Explore related questions
See similar questions with these tags.
lang-js