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

272
Views
How to use filter to compare to arrays to find missing object?

I'm trying to use arr.filter() to find the missing element between two arrays, this has been answered plenty of times and i've seen threads like this one Finding missing element in two array for javascript that explain it actually very well. For some reason thought, i cant seem to get this to work.

This is my code

var x = [{Number:1},{Number:2},{Number:3}]
var y = [{Number:1},{Number:2}]

function getDifference(x,y){

    x.filter(function(object,index,arr){
        console.log(object,index,arr)
        if(!y.includes(object)){
            // print object
            console.log(object) // <-- Prints all 3, should just print the missing one.
        }
    })

}

getDifference(x,y)

Basically, it just needs to print out the missing object. Which in this case, is {Number:3} Instead, it prints every object.

I've tried with the code in the thread that i linked above, and still was having trouble. Not sure what i'm not understanding with it.

about 4 years ago · Juan Pablo Isaza
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!