• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

215
Views
How to filter Object with multiple keys inside

I'm a beginner. Imagine data being like this on a js file :

const myData = {
  1: {
    1: {
      displayText: "word1",
      text: "worddisplay1",
    },
    2: {
      displayText: "word1",
      text: "worddisplay1",
    },
    3: {
     displayText: "word3",
      text: "worddisplay3",
    }
  },
 2: {
    1: {
      displayText: "word4",
      text: "worddisplay4",
    },
    2: {
      displayText: "word5",
      text: "worddisplay5",
    },
    3: {
     displayText: "word6",
      text: "worddisplay6",
    }
  }
}

I would like to do a search filter in this data, in javascript.

For example, if i enter the word "display1", it will give me all the results containing the word "display1".

I tried like this :

 Object.keys(myData).forEach((k) => {
      console.log(k, myData[k]);
    });

But i don't know what I have to do after, should I use a forEach inside a forEach? I know I have to use the "includes" keyword.

If someone can bring me the trick, i'm being stuck for days

about 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

try this.


Object.values(myData)
  .flatMap(it => Object.values(it))
  .filter(it => it.displayText.includes('word1'));

about 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error