Question: Using JSON in Javascript I have an array I wrote in Javascript and I'm trying to figure out how to use it with JSON. I

Using JSON in Javascript

I have an array I wrote in Javascript and I'm trying to figure out how to use it with JSON. I am trying to find the largest age of the person in this group, and then use that age to get their name and print both the name and age at the end. In Javascript, I have it like this: (how would I do this with JSON?)

var array = [ {name: 'Belinda', age: 30}, {name: 'Kim', age: 15}, {name: 'Jessica', age: 35}, {name: 'Amy', age: 56}, {name: 'Becky', age: 16} ];

maxVal = -1 indexVal = -1 for (i = 0, len = array.length; i < len; i++) { if(maxVal < array[i].age){ indexVal = i; maxVal = array[i].age; } } console.log(array[indexVal].name); console.log(array[indexVal].age);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!