Skip to content

Instantly share code, notes, and snippets.

@geomago
Last active June 19, 2020 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geomago/80bc5b00f7c0092a88a3cd3327d218d0 to your computer and use it in GitHub Desktop.
Save geomago/80bc5b00f7c0092a88a3cd3327d218d0 to your computer and use it in GitHub Desktop.
intersect_arrays
let commonCars = cars.filter( item => cars2.findIndex( car => car.id == item.id ) >= 0 );
// RESULT IS:
[
{id:2,make:"Ferrari",model:"F8 Spider",price:262000,colour:"giallo modena"},
{id:5,make:"McLaren",make:"New GT",price:203000,colour:"helios orange"},
{id:6,make:"Ferrari",model:"F8 Spider",price:262000,colour:"giallo modena"}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment