Find absolute max value in Javascript array
Math.max.apply(null, array.map(Math.abs));
If you target browsers that don't support Array.prototype.map (IE<=8), use the polyfill or a library like sugar.js.
Try this:
var array = [10,20,40,-30,-20,50,-60];
var absMax = array.reduce(function(max, item){
return Math.max(Math.abs(max),Math.abs(item));
});
How this
var array = [10,20,40,-30,-20,50,-60];
return Math.max(...array.map(a => Math.abs(a)))