[1000,4000,8000,12000,16000]
var prices = [1000,4000,8000,12000,16000];
var price = 18000;
var diff = prices.map(a=>Math.abs(a-price));
diff.indexOf(Math.min(...diff))
let arrayForTest = [1000,4000,8000,12000,16000];
function checkIndex(array, number) {
let resultIndex;
array.some((elem, index, array) => { number > elem && ( number < array[index + 1] || index === array.length - 1) ? (resultIndex = index) || true : false });
return resultIndex;
}
checkIndex(a, 1500) //0
checkIndex(a, 4500) //1
checkIndex(a, 19000) //4