JSFiddle - React, Tailwind, and code Playground

by pierian_design

JavaScript

let a = [1, 220, 434, 648, 862, 1076, 1290, 1504, 1718, 1932], 
b = 3;
console.log(a.sort((x, y) => Math.abs(b - x) - Math.abs(b - y) )[0]);