Saturday, 5 September 2020

How do I map through group of two or more Arrays to get a length result?

enter image description hereI have two or more Arrays with inputs

this.listNumber = [
  {
    "GenericQuestions": [
      {
          "input": "long",
      },
      {
          "input": "dog",
      },
      {
          "input": "",
      }
    ],
  },
  {
    "GenericQuestions": [
      {
          "input": "fred",
      },
      {
          "input": "barney",
      },
      {
          "input": "betty",
      }
    ]
  }
]

// can be more Arrays

I have previously used this getFilter Method to get the results of inputs with values from a single Array

getFilter(index: string | number) {  // index being 0
    return this.listNumber[index].GenericQuestions.filter((c: { input: any }) => !!c.input).length;
} // returns 2

What I am trying to figure out is how I would get results of inputs filled out from both Arrays.

I even tried

  const flatfile = this.listNumber.flat();
  console.log("flatfile", flatfile);

But I think it failed because GenericQuestions are inside separate objects.



from How do I map through group of two or more Arrays to get a length result?

No comments:

Post a Comment