I'm a JSON/Javascript newbie and have a problem of this nature.
within my php script I'm passing a php array to javascript as follows:
echo '<img id="Next" src="misc/arrow_right.png" onclick="imageSlider(' . json_encode($images) . ')" >';
in my javascript:
function imageSlider(imagesArray) {
alert(imagesArray);
}
the alert above prints an output of the form object Object
The trouble is I do not know how best to 'decompose' or break down this object so that I can extract its the data that I originally json_encoded.The structure of the original array is a simple numeric indexed array with strings i.e ["image1", "image2",...] etc
I have also tried alert(JSON.stringify(imagesArray)) and I get this string:
{"1":"images1.jpg","2":"images2.jpg","3":"images3.jpg","4":"images4.jpg","5":"images5.jpg"}
Either way I am not sure how best to get my images names and array index in javascript. e.g extract 1 and images1.jpg from the object or if there is a way to convert the 'stringified' object into a true javascipt array...? Thanks