I have an array of objects. The objects have a property called level that is a string which contains a number and is in consistent format.
I am trying to find the highest number and return just that one but I seem to be blocked as far as how to proceed from my current code.
Here is a fiddle to my current code: http://jsfiddle.net/6sXYR/
Here is my JavaScript:
var myArray = [
{
color: 'blue',
level: 'L1'
},
{
color: 'red',
level: 'L1'
},
{
color: 'green',
level: 'L2'
},
{
color: 'yellow',
level: 'L2'
},
{
color: 'purple',
level: 'L3'
}
];
for (var i = 0; i < myArray.length; i++) {
console.log( myArray[i].level.substring(1,2) );
};
The result I am trying to get is to return just the number '3' from the example above. The highest number may not always be in the last object in the array, but it will always be in the format of L#.