skip to Main Content

I receive answer from a form. I receive an array with objects where each object correspond to the answer of one question:

I want to access the answer.

First I was thinking to ask to use answers[i].t (for example), but the problem is that the number of the question depends of the answers submitted so I can’t use index of the array. So I had the idea to access to the answer by using the id of the question.

For example: object.t where object.q === "64c3980b7e457155fed418db".

How can I do that in JavaScript?

2

Answers


  1. const getId = answers?.findIndex(object.q === "64c3980b7e457155fed418db");
    
    Login or Signup to reply.
  2. Use the find method:

    answers.find(item => item.q  === "64c3980b7e457155fed418db");
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search