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

97
Views
javascript - check if array object contains a array by values

trying to check if a value of array present on a base array and return as string-

base array:

const filters = {
    "name: "location",
    "data" : [
        "dana-point",
        "canada-so"
    ]
}

const posts = [
    {
        "date": "09 February 2022",
        "title": "There are many variations of passages of Lorem Ipsum available",
        "locations": [
            "dana-point",
            "new-york"
        ],
        "url": "/news/many-variations",
    },
    {
        // so may items
    },
]

I wanted to return all post which matched with filter data object with at least one value match like - on above example it will retrun first post as its match the location, dana-point.

let filteredPosts = posts.filter(item => checks.includes(item[checks.data])));

it's not working

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

0

You can do something like this:

const checks = [
  {
    name: "locations",
    data: ["dana-point", "canada-so"]
  }
];

const posts = [
  {
    date: "09 February 2022",
    title: "There are many variations of passages of Lorem Ipsum available",
    locations: ["dana-point", "new-york"],
    url: "/news/many-variations"
  }
];

const filtered = posts.filter((post) =>
  checks.every((check) =>
    post[check.name].some((data) => check.data.includes(data))
  )
);
about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!