After running my code, I believe it returns a JSON array. The resulting JSON array is then stored in a JavaScript variable called 'result'. When I
console.log(result);
in Firefox, the output shown is:
[{"id":"G24","value":"Zas, S"},{"id":"G75","value":"Wara, TS"},{"id":"G48","value":"Jala, S"}]
This has been validated on jsonLint to confirm that it is indeed correct JSON.
In my code, when I attempt to count the number of elements in the array with this code snippet:
var key, count = 0;
for(key in result)
{
count++;
}
console.log("The count of results is:" + count);
The output displayed is 94, which represents the length/character count of the array - [the example output above has been modified]
However, within the JSON tab in Firefox, it displays the results as an array of objects:
0 Object { id="G24", value="Zas, S"}
1 Object { id="G75", value="Wara, TS"}
2 Object { id="G48", value="Jala, S"}
I have also tried using different code snippets from various sources including 'stackoverflow' resources
for ( property in result )
{
if(result.hasOwnProperty(property))
{
count++;
}
}
Yet, the outcome remains the same. How can I accurately iterate over this array or array of objects or string, and determine the count? Any guidance would be greatly appreciated. Thank you.