Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8965711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:52:08+00:00 2026-06-15T16:52:08+00:00

How can I turn this array of objects (which has some duplicate objects): items

  • 0

How can I turn this array of objects (which has some duplicate objects):

items =
  [
    { TYPEID: 150927,  NAME: 'Staples',    COLOR: 'Silver' },
    { TYPEID: 1246007, NAME: 'Pencils',    COLOR: 'Yellow' },
    { TYPEID: 1246007, NAME: 'Pencils',    COLOR: 'Blue'   },
    { TYPEID: 150927,  NAME: 'Staples',    COLOR: 'Black'  },
    { TYPEID: 1248350, NAME: 'Staples',    COLOR: 'Black'  },
    { TYPEID: 1246007, NAME: 'Pencils',    COLOR: 'Blue'   },
    { TYPEID: 150927,  NAME: 'Staples',    COLOR: 'Silver' },
    { TYPEID: 150927,  NAME: 'Fasteners',  COLOR: 'Silver' }
  ]

Into this:

items =
  [
    { TYPEID: 150927,  NAME: 'Staples',    COLOR: 'Silver' },
    { TYPEID: 1246007, NAME: 'Pencils',    COLOR: 'Yellow' },
    { TYPEID: 1246007, NAME: 'Pencils',    COLOR: 'Blue'   },
    { TYPEID: 150927,  NAME: 'Staples',    COLOR: 'Black'  },
    { TYPEID: 1248350, NAME: 'Staples',    COLOR: 'Black'  },
    { TYPEID: 150927,  NAME: 'Fasteners',  COLOR: 'Silver' }
  ]

…by filtering out the two duplicate objects (the silver staples and the blue pencils)?

It seems like there should be an easy way to do this, but I’ve yet to find a simple solution.

I’ve seen some javascript / jquery code which does this, but I’m not the best at converting those into coffeescript.

UPDATE:

There will often be different objects with the very similar properties.

In the actual application, each object has a potential of 25 properties.

I only want to remove objects if each of those properties are equal.

UPDATE 2

This is the code that ended up working for me – (thanks to rjz)

unique = (objAry, callback) ->
  results = []

  valMatch = (seen, obj) ->
    for other in seen
      match = true
      for key, val of obj
        match = false unless other[key] == val
      return true if match
    false

  objAry.forEach (item) ->
    unless valMatch(results, item)
      results.push(item)
  callback null, results

And this is how I’ll call it:

unique items, (err, items) ->
  console.log items
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:52:09+00:00Added an answer on June 15, 2026 at 4:52 pm

    Depending how deeply you want to check equality, you could probably just assume uniqueness of the USERID field and do something like this:

    ids = []    # Contains list of "seen" IDs
    result = [] # Contains list of unique users
    
    users.forEach (u) -> 
      if result.indexOf(u.USERID) == -1
        result.push(u)
        ids.push(u.USERID)
    

    If you need to do deeper matching and don’t have a primary key available (might be a sign of bigger issues), you could create a more sophisticated test for equality:

    valMatch = (seen, obj) ->
      for other in seen
        match = true
        for key, val of obj
          match = false unless other[key] == val
        return true if match
      false
    
    result = []
    seen = []
    
    data.forEach (datum) -> 
      unless valMatch(result, datum)
        result.push(datum)
        seen.push(datum)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm adding an array of Panel objects (which in turn contain other items) to
How I can turn this Array ( [0] => feed [1] => entry )
Without foreach , how can I turn an array like this array(item1=>object1, item2=>object2,.......item-n=>object-n); to
How can I turn this behavoir off? It happens when you enter a close
I have a CGContext, which I can turn into an NSGraphicsContext. I have an
I have an single-dimensional array of PHP objects. Each object has two attributes, one
I've got a tree which is populated by Node objects. Each node has an
The prototype of some native javascript objects can be extended to include new functions
So I know I can turn warnings into errors using -Werror=... but I want
I'd like a daemonizer that can turn an arbitrary, generic script or command into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.