aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

JavaScript - Remove Duplicate Values from Arraylist String

Mar 12, 2013

Here I will explain how to use JavaScript to remove duplicate values from array or remove duplicate values/elements from string array using JavaScript


In previous article I explained Show number of characters left in text using JavaScript, Set watermark text for textbox using JavaScript, JavaScript Automatically move cursor to next field when textbox full , JavaScript add bookmark link to website and many articles relating to JavaScript, jQuery, SQL, etc. Now I will explain how to remove duplicate values/elements from string array using JavaScript.

To remove duplicate values/elements from string array using JavaScript we need to write the code like as shown below

<html xmlns="">
<title>Remove duplicates from an array using JavaScript </title>
<script type="text/javascript">
function RemoveList() {
var sampleArr = new Array(1, 1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4); //Sample array
//Adds new uniqueArr values to temp array
function uniqueArr(arr) {
arr1 = new Array();
for (i = 0; i < arr.length; i++) {
if (!checkstatus(arr1, arr[i])) {
arr1.length += 1;
arr1[arr1.length - 1] = arr[i];
// Check if it contains unique or duplicate record
function checkstatus(arr, e) {
for (j = 0; j < arr.length; j++) if (arr[j] == e) return true;
return false;
<input type="button" value="Remove Duplicates" onclick="RemoveList()" />
Live Demo

For live demo click on below button it will return only unique values from this string (1, 1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4) values

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Anonymous said...

nice example..

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.