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

134
Views
How to get array of objects based on object and array list in javascript

I have an array of object, a object, and an arraylist.

I have to get the array of objects based on conditions using javascript:

  1. Fetch the array of objects if the value property matches with object item

  2. Check if the code value exists in the arraylist arraylist, if exists return array ibject

  3. Else return empty

var arrobj1 =[
  {id:1, name: zen, code: "SP", value: 100},
  {id:2, name: abi, code: "IN", value: 200},
  {id:3, name: lisa, code: "SG", value: 200}
]
var arraylist =["IN"]
var obj1={
  id:34, code: "SP", country: "mexico", item: 200
}

Expected Output:

// value & item matches, code does not exists so empty []

var arrobj2 =[
  {id:1, name: zen, code: "SP", value: 300},
  {id:2, name: abi, code: "SP", value: 200},
  {id:3, name: lisa, code: "SG", value: 100}
]
var arraylist =["IN"]
var obj2={
  id:34, code: "SP", country: "italy", item: 100
}

Expected Output

// value & item matches, code matches

[
    {id:3, name: lisa, code: "SG", value: 100}
]

I have tried using below code:

var result = arrobj1.some(e => {
        if (e.value === obj.item &&
          (arraylist.includes(e.code)){
            return true;
        }
        return false;
      });
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

First filter items, then use some.

let filtered = arrobj1.filter(({value}) => value == obj1.item)
let result = filtered.some(({code}) => arraylist.includes(code)) ? [] : filtered
about 4 years ago · Santiago Trujillo 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!