Home > database >  I want to select a date array data (type : string) from a object of dates
I want to select a date array data (type : string) from a object of dates

Time:12-24

I am trying to access the array data of a specific date, I have created a date variable which stores the value (eg. 27/12/2022), But I can't figure out how to access the specific date from the object of various dates.

API Data : Date Object with array data of timings in it.

1

I just want to access the timings data for any selected date.

I tried the normal way of selecting the variables in an object. eg. (timeGroup.formattedDate) here formattedDate is the constant storing my selected date. getTimeDet() is a function from Context API which just sends the object and it gets stored in the timeGroup constant.

useEffect(() => {
    if(date === '') return;

    const [year, month, day] = date.split('-');
    const formattedDate = [day, month, year].join('/');
    console.log(formattedDate);

    const timeGroup = getTimeDet();
    console.log(timeGroup);

  },[date])

CodePudding user response:

access like this: timeGroup[formattedDate]

you need to use formattedDate value to get from the object.

  • Related