Hello everyone. What I am trying to do is validate an object that is between a range of numbers
Well what I am trying to do is compare an object that is between a range of numbers as the following code shows.
const data = [
{ id: 843, hora_ingreso: '11:44:56 AM', hora_salida:'11:47:57 AM',},
,{ id: 845, hora_ingreso: '8:01:32 PM',hora_salida: ''}
,{ id: 846, hora_ingreso: '9:11:20 PM',hora_salida: '12:13:51 PM',}
,{ id: 847, hora_ingreso: '10:13:35 PM',hora_salida: '12:13:45 PM',}
,{ id: 848, hora_ingreso: '11:48:13 PM',hora_salida: '12:48:20 PM',}
,{ id: 848, hora_ingreso: '2:48:13 PM',hora_salida: '12:48:20 PM',}
,{ id: 848, hora_ingreso: '1:48:13 PM',hora_salida: '12:48:20 PM',}
,{ id: 848, hora_ingreso: '3:48:13 PM',hora_salida: '12:48:20 PM',}
,{ id: 846, hora_ingreso: '9:55:20 PM',hora_salida: '12:13:51 PM',}
];
// aqui quiero insertar un metodo que pueda retornarme los valores de
// data.hora_ingreso >= 8 && data.hora_ingreso =< 12
// El Objeto deberia de retornarme entre data.hora_ingreso >= 8, 9, 10, 11, 12
/*
lo que quisiera que me retorne es :
{ id: 843, hora_ingreso: '11:44:56 AM', hora_salida:'11:47:57 AM',},
,{ id: 845, hora_ingreso: '8:01:32 PM',hora_salida: ''}
,{ id: 846, hora_ingreso: '9:11:20 PM',hora_salida: '12:13:51 PM',}
,{ id: 847, hora_ingreso: '10:13:35 PM',hora_salida: '12:13:45 PM',}
,{ id: 848, hora_ingreso: '11:48:13 PM',hora_salida: '12:48:20 PM',}
,{ id: 846, hora_ingreso: '9:55:20 PM',hora_salida: '12:13:51 PM',}
*/
let date = data.filter( e => e.hora_ingreso >= '8');
console.log( date );
Try to do between income_hour >= '8' && income_hour <= '12' but when it reaches 12 it filters the other numbers as an example 1,2,3,4,5,6,7,8,9,10,11,12 and in this way the validation loses meaning
One solution would be to split the value of
hora_ingreso
and take the first element of the array and compare it.I think the best thing would be to use a complete time format with everything and date so that you can parse using
Date
. But in case you don't have control over the origin of the data, I recommend you usemomentjs
and parse the dates with the format you need.Result:
Now with this parse you can do things like:
Result: