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?

2

3 Answers 3

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
    }
]
Sign up to request clarification or add additional context in comments.

Comments

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.

2 Comments

But then i use something like var name = marr[i].name to get array values, so i need "titles" for array items...
Updated my answer.. Now marr[1].name will give you Spot 1
1

this will be json representation of array

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.