Introduction:
This article will helps you in removing any duplicate values from Multi Dimensional Array using simple JavaScript. Here I have used a simple logic, hope everyone can understand. Even, this article will help beginners in learn some simple tricks in JavaScript.
JavaScript Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | <!-- Author: K.Vivekanand (http://www.developersnippets.com) --> <!-- Contact: vivek@developersnippets.com --> <script type="text/javascript"> var testArray = [ [3, "Adobe"], [3, "Adobe India"], [5, "Photoshop"], [4, "Flash"], [1, "Bridge"], [4, "Flash CS3"], [3, "Adobe Gumbo"] ]; var tempArray = new Array(); tempArray[0]=testArray[0]; for(var i=0;i<testArray.length;i++) { var flag = true; for(var j=0;j<tempArray.length;j++) { if(tempArray[j][0]==testArray[i][0]) { flag = false; } }//for loop if(flag==true) tempArray.push(testArray[i]); }//for loop document.write(tempArray); </script> |
I am removing values depending on first element in the array that is 3,3,5,4,1,4,3. If you look at this one 3 and 4 are repeated twice. After applying simple logic, the output would be:
OutPut:
3,Adobe,5,Photoshop,4,Flash,1,Bridge
If you want to same concept for one dimensional array that is simple array, then you can view this article for reference – Remove duplicates from an array using JavaScript
Related Entries...
Here is a simple and easily understandable snippet code, to remove duplicates from an existing array ...
Introduction: I would like to say this article going to help most of the developers who are in need ...
Introduction Recently, one of my reader came up with a query like "Why JavaScript is not running aft ...
In the following article we can have a look at the ways of creating new files in Ruby programming lan ...
In some scenarios we will have catch hold of number of occurrences while coding, like for example: In ...
I am back again with some helpful snippet code. Here using JavaScript we can pro actively sort date f ...
Hi Guys, I would like to share a JavaScript snippet code which will remove special characters (like ! ...
Last week, I had a problem with flash object which is rendering dynamically on to my web pages. Actua ...
After going through this article, you will get an idea on resolving browser compatibility issues whil ...
Here is a simple snippet on adding a "div" to the body tag dynamically using JavaScript, after going ...























2 Responses
This is really cool and easy ……. havent thought that must be so easy
Works great, perfect for what i was looking for! Thanks!