[{"id":1},{"id":2},{"id":3}]
I know I can use max like this var largest = Math.max.apply(Math, myArray) (if I have my array like this [1,2,3]
) but since I have to loop through a list, I just wonder I can use loop to get the largest number;
$.each(function(){
//this.id
// how to continue here?
});
You can still use the Math.max.apply
construct. Simply use map
to make an array of ids from the objects:
var maxId = Math.max.apply(Math, myList.map(function(o){ return o.id }));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With