0

I have 5 categories, each category has 3 items.

I have the array:

var myArray = ["Item1", "Item2", "Item3"];

What is the easiest way to create a Json from it without hardcoding it ?

The array in production can have thousands of items.

3
  • 1
    JSON.stringify( javascriptVariable) Commented Jul 13, 2013 at 22:25
  • And that variable I create it normally with fors and ifs ? Commented Jul 13, 2013 at 22:26
  • Doesn't matter, whichever variable you want to jsonize, you can via the above command. Maybe you should post your code to show exactly what you want. Commented Jul 13, 2013 at 22:27

1 Answer 1

1

Use pure javascript:

JSON.stringify(myArray);

You can use json.js for compatibility with <=IE7

Sign up to request clarification or add additional context in comments.

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.