When dealing with an array, remember to access elements using their index position.
To retrieve items from an array, use nameOfMyArray[Index]
. In this case, it would be nameOfYourArray[0]
(keep in mind that the first item is at index 0).
var myStudent = [ 'Alex',
{ id: '0.0010733333111112',
grade: 'N/A',
street: 'N/A',
zip: 'N/A',
hobby: 'soccer' } ];
alert(myStudent[0])
If you need to iterate over your list of students:
for (var i in myStudentList) {
alert(myStudentList[i][0]);
}
Whether your students are in JSON format is irrelevant since you converted the JSON string into an array of students, each resembling a student like Alex in your example.
Consider storing your students as key-value pairs (name and information dictionaries) rather than as an array of dictionaries, as shown here:
var myStudent = { 'Alex':
{id: '0.0010733333111112',
grade: 'N/A',
street: 'N/A',
zip: 'N/A',
hobby: 'soccer'}
}
If you adopt this approach, you can retrieve the names of all students using:
alert(myStudentList.Keys())