const a = 50 ;
const x = [{
from: 0,
to: 100,
color: "red",
},
{
from: 100,
to: 200,
color: "blue"
}
]
let res = x.filter ( (item)=>{
if ( ( a >= item.from ) && ( a <= item.to ) ){
return true;
} else {
return false
}
} );
let res = x.forEach ( (item)=>{
if ( ( a >= item.from ) && ( a <= item.to ) ){
console.log ( 'Element spełnia warunek', item );
}
} );
const color = x
.filter(c => c.from <= a && a < c.to)
.map(c => c.color)[0]
const color = x.find(c => c.from <= a && a < c.to).color;