Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

find property inside nested array javascript

I have an object that contains data to display information pulled from the Notion API. I can see the data but not sure how I can extract nested array inside the current array. My goal is to use the category property to create a filter but first I need to get the string to create the condition.

Here is what the data looks like currently. How would I go about to filter out name: "commissions":

resultsArray:
  0:
      properties
      category:
        id: "sdasd"
        multi_select:
          0:
              id:"324234"
              name: "commissions"

I have tried use find but it doesn’t do what I expect. My suspicion is that I will have to loop over the nested array again.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use find inside find condition

like this :

data.resultsArray.find(item=>item.category.multi_select.find(select=> select.name === "commissions"))
const data = {
  resultsArray: [
    {
      category: {
        id: 'sdasd',
        multi_select: [
          {
            id: '324234',
            name: 'commissions',
          },
        ],
      },
    },
  ],
};

const result = data.resultsArray.find(item=>item.category.multi_select.find(select=> select.name === "commissions"))

console.log(result)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading