Storing JSON Array in a Hidden HTML element
html, javascript, json
Solution
Essentially, you want to serialize your array into json, and then specify where you want to store the resulting string value..
document.getElementById('yourHiddenField').value = jsonString;
Problem
I have a JSON Array that is defined as follows: ``` var myItems = { "data": [ { "id":1, "firstName":"bill", "lastName":"smith" }, { "id":2, "firstName":"john", "lastName":"apple" }, { "id":3, "firstName":"will", "lastName":"long"} ] }; ``` I need to store this array in a hidden HTML element so that I can pass it to my server-side code in string format. My problem, I'm not sure how to do this. Can someone tell me how to do this? Thank you!