I'm with a small problem that can not be solved. I need something in javascript that takes only the value closest to zero in an array. The array is the following:
[{priority: 0, instance: "DNI"}, {priority: 1, instance: "CUIT"}, {priority: 2, instance: "CEDULA_IDENTIDAD"}] What I need, is some function that stays only with:
{priority: 0, instance: "DNI"} thank you!
data = [{...}]; data.reduce((p, c) => Math.abs(c.priority) - Math.abs(p.priority) < 0 ? c : p, data[0]);