I am working with a multidimensional array called 'dataArray' which has the following structure.
dataArray = [ {name:"Apples", score: 3.5}, {name:"Oranges", score: 3.7}, {name:"Grapes", score: 4.1} ];
My goal is to find the highest score along with its corresponding name from the dataArray.
function playerArray() {
dataArray = [{
name: "Apples",
score: 3.5
}, {
name: "Oranges",
score: 3.7
}, {
name: "Grapes",
score: 4.1
}];
for (i = 0; i < dataArray.length; i++) {
var nameArray = dataArray[0].name;
var scoreArray = dataArray[0].score;
var largest = Math.max.apply(Math, scoreArray);
alert(largest[0].score);
}
}
When I run the 'playerArray()' function, it raises the following error: test.html:24 Uncaught TypeError: CreateListFromArrayLike called on non-object at playerArray