0

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.

1
  • If the answer is helpful, give credit to the person who gave the answer and give them a +1 Commented Feb 13, 2023 at 7:46

1 Answer 1

1

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)

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.