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

207
Views
How to filter an array using another array in Javascript?

I have an array of objects that has "number" property in it, i want to filter this array based on the "number" property through an array of numbers called "filteredNumbersArray"

i tried this but it doesn't make any changes to the array

const remaining = phones.filter(
          (data) => !((data.number as number) in filteredNumbersArray),
        );

const remaining is the filtered phones array.

phones is my array of object, my object has a field number: number

example on data in phones: [{number: 5}, {number:2}]

filteredNumbersArray is an array of numbers. ex.[1,2,3]

i want result to be [{number:5}] based on the above example.

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

0

you could use array.includes to know if it contain an element

const phones = [{number: 5}, {number:2}] ;
const filteredNumbersArray = [2,4,6];
console.log( phones.filter( e => !filteredNumbersArray.includes(e.number) ) );

https://jsfiddle.net/fgsrjnm6/

about 4 years ago · Juan Pablo Isaza Report

0

You want to use includes when dealing with filteredNumbersArray.

const remaining = phones.filter(data =>
  !filteredNumbersArray.includes(data.number)
)
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!