You can filter your array so that you get an array with numbers that are smaller than your goal number. Once you have this array, the largest number in that array will naturally be the closest number to goal, which you can obtain by spreading your array into Math.max():
const counts = [4, 9, 15, 6, 2],
goal = 13;
const closest = Math.max(...counts.filter(num => num < goal));
console.log(closest);
One thing to note, the above will struggle with large arrays (mainly due to the fact that Math.max() has an argument limit), a more optimised option would be to use a regular loop, for example:
const counts = [4, 9, 15, 6, 2], goal = 13;
let closest = -Infinity;
for(const num of counts)
if(num < goal && num > closest) closest = num;
console.log(closest);