0

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])

1 Answer 1

1

access like this: timeGroup[formattedDate]

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.