I need to return the position of the element closest to zero without being a negative number.
I have 4 roll sizes(in”) to cut film from. I’m trying to enter a width variable and subtract from the elements of the array and the closest to 0 will return the array position of the best roll size. I hope this makes sense. Thanks.
var width = ""
var rollArray = [36, 48, 60, 72]
var newArray = []
for(i in rollArray){ newArray.push ((rollArray[i]) - width) }
alert(newArray);
returns width minus each element, now I need to find how to return the lowest values array position so that I can get the roll size from the equivalent rollArray position.
1 Answer