# Coding Challenge - Remove Duplicate Objects

**URL:** <https://forum.kirupa.com/t/coding-challenge-remove-duplicate-objects/684024>\
**Category:** Uncategorized\
**Created:** [November 14, 2026, 5:55am UTC](https://forum.kirupa.com/t/coding-challenge-remove-duplicate-objects/684024 "2026-11-14T05:55:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Apexcodes](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/apexcodes/32/33967_2.png) [@Apexcodes](https://forum.kirupa.com/u/Apexcodes)\
**Post date:** [November 14, 2026, 5:55am UTC](https://forum.kirupa.com/t/coding-challenge-remove-duplicate-objects/684024/1 "2026-11-14T05:55:07Z")

</div>

Write a function `uniqueBy(items, key)` that removes duplicate objects based on a specified property.

Example:

```auto
const users = [
  { id: 1, name: "Alex" },
  { id: 2, name: "Sam" },
  { id: 1, name: "Alex Updated" },
  { id: 3, name: "John" }
];

uniqueBy(users, "id");

```

Expected result:

```auto
[
  { id: 1, name: "Alex" },
  { id: 2, name: "Sam" },
  { id: 3, name: "John" }
]

```

**Rules:**

- Plain JavaScript, no libraries.

- Do not mutate the original array.

- Keep the first occurrence of each key.

- Try to solve it in O(n) time.

How would you implement it?
