Find the closest smaller value of an array

Reverse the array and use find

let arr = [0, 38, 136, 202, 261, 399];
let val = 300;
let number = arr.reverse().find(e => e <= val);
console.log(number);


If you array is sorted, and small enough, a really simple mode to do what you want it's simplly iterate over the array until number > number-in-array then return the number on the previous position.

function getClosestValue(myArray, myValue){
    //optional
    var i = 0;

    while(myArray[++i] < myValue);

    return myArray[--i];
}

Regards.