Get the nearest value in a JavaScript array of objects using reduce

let values = [{id : 1, value : "one"},{id : 2, value : "two"},{id : 3, value : "three"},{id : 4, value : "four"}]

let total = 2.1;

let result = values.reduce((prev,curr) => {
  console.log(`for ${prev.id} ${curr.id}`)
  if(Math.abs(total - prev.id) < Math.abs(total - curr.id) ){
    return prev
  }else{
    return curr
  }
})

console.log(result)

This will print the object with id nearest to total