Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
Filter nested array in object based on specific values of another array

I have an array of Objects, and every object has an array of strings (tags), I need to filter the array of objects based on another array.

data: [
       {
          "id":"Nerium",
          "tags":["CMS Selection", "Experience Design", "Development","UX"],
          "featured":0
       },
       {
          "id":"WesternDigital",
          "tags":["Digital Strategy", "Analytics", "Example"],
          "featured":1
       },
       {
          "id":"Example",
          "tags":["Example", "Analytics", "UX"],
          "featured": 0,
       },

I need to filter the above data based on an Array like this:

activeTags: ['UX', 'Example']

And the objects of Data I filter need to specifically have the values inside activeTags, in this case if for example an Object has 'UX' but it doesn't have 'Example', I don't return it.

Expected output:

data: [{
  "id": "Example",
  "tags": ["Example", "Analytics", "UX"],
  "featured": 0,
}]

Or it should return every Object that has tags that specifically have the values in activeTags

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

I haven't tested, but I think the following should work:

const result = data.filter( record =>
    activeTags.every( tag =>
        record.tags.includes( tag )
    )
);

filter() returns array with only elements that pass its function test. every() returns true only if every element passes its function test. includes() will test if the element is included in the record.tags array.

about 4 years ago · Santiago Gelvez Report

0

This should work

const data = [
  {
    id: "Nerium",
    tags: ["CMS Selection", "Experience Design", "Development", "UX"],
    featured: 0,
  },
  {
    id: "WesternDigital",
    tags: ["Digital Strategy", "Analytics", "Example"],
    featured: 1,
  },
  {
    id: "Example",
    tags: ["Example", "Analytics", "UX"],
    featured: 0,
  },
];

const activeTags = ["UX", "Example"];

const filtered = data.filter(({ tags }) =>
  activeTags.every((tag) => tags.includes(tag))
);

console.log(filtered);

you can use .every to check that the object has all the active tags

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!