:::: MENU ::::

Rick Groenewegen · Senior Coldfusion, SQL, NodeJS and Mobile developer

Senior Coldfusion, SQL, NodeJS and Mobile developer

Removing duplicates from an array

  • Sep 06 / 2013
  • 0
bender
Coldfusion

Removing duplicates from an array

Last week I was looking for a way to remove duplicate items from an array in ColdFusion without having to loop over every element. Turns out it was really simple using:

<cfset myArray = [1,2,2,5,9,9,7,8,8,8]/>
<cfset myArray = createObject("java", "java.util.HashSet").init(myArray).toArray()

<!--- Result: [1,2,5,9,7,8] --->
<cfdump var="#myArray#"/>

Leave a comment

Need to know more? Contact me!