JavaScript filter() not working as expected - returns empty array with valid data
01:17 15 Nov 2025

I'm filtering customer data to find duplicates based on email. My filter returns an empty array even though I know duplicates exist.

const customers = [
    { id: 1, email: 'test@example.com', name: 'John' },
    { id: 2, email: 'test@example.com', name: 'Jane' },
    { id: 3, email: 'other@example.com', name: 'Bob' }
  ];
 
  const duplicates = customers.filter((customer, index, arr) =>
    arr.findIndex(c => c.email === customer.email) !== index
  );
 
  console.log(duplicates); // Expected: [{id: 2, ...}] but got: []

What am I doing wrong? How can I correctly find duplicate emails?

javascript arrays filter duplicates