473,785 Members | 2,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deleting repeated values in array

12 New Member
hi,

I have a issue with an array values... Im having values repeatedly stored in an array and i want to delete those repeated values using javascript.
* I tried it by storing in an array and sorting it using the blank spaces
* I used regexp for it replace it an order

but i cant find a solution... anybody have a nice result for it... help me pls... I expect it with an example with code...

gemguy
Apr 18 '07 #1
3 2263
acoder
16,027 Recognized Expert Moderator MVP
Define a new array which will store the non-duplicate values. Then loop through the array which contains the values.

In each iteration, check if the non-duplicate array contains the value. If it does, ignore it. If it doesn't add it to the array.

I think someone did something similar recently. If I find it, I'll link to it (I can't be bothered rewriting it).
Apr 18 '07 #2
acoder
16,027 Recognized Expert Moderator MVP
See this post. You'll have to adapt it - it was for a specific question.
Apr 18 '07 #3
mrhoo
428 Contributor
The most general way is to assign a method for removing duplicates to all Arrays-
but first define indexAt.

Expand|Select|Wrap|Line Numbers
  1. Array.prototype.indexAt= function(wot){
  2.     var L= this.length;
  3.     var i= 0;
  4.     while(i< L){
  5.         if(this[i]=== wot)return i;
  6.         ++i;
  7.     }
  8.     return -1;
  9. }
And then the method that removes duplicates:
Expand|Select|Wrap|Line Numbers
  1. Array.prototype.unique= function(){
  2.     var A= [],L,tem;
  3.     L= this.length;
  4.     for(var i= 0;  i< L;  i++){
  5.         tem= this[i];
  6.         if(A.indexAt(tem)!=-1)continue;
  7.         A.push(tem);
  8.     }
  9.     return A;
  10. }
var A2=someArray.un ique(); or someArray=someA rray.unique()
Apr 18 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
2882
by: Andres Eduardo Hernando | last post by:
Hi, I'm not entirely sure this is the right group to ask this question, but I saw a similar one above, and the group's charter is not clear enough about it, so, here I go: ;) What is the standard behavior (if any) when the same name is attached to more than one field in a <form>? An example (that closely resembles the problem I'm working on) will be (this is a standard radio group without a default selected option): <form ...> <input...
18
2482
by: Dan | last post by:
hello, I would to know if it is possible to delete an instance in an array, The following does not allow me to do a delete. I am trying to find and delete the duplicate in an array, thanks for ( j =0; j<MAX ; j++) { for ( i =0; i<MAX ; i++)
7
1775
by: Geoff Cox | last post by:
Hello, For some reason, which I cannot see, the code below repeats the last element of the array at the beginning of the data sent via email. Can onyone see why? Thanks Geoff
16
2149
by: Josué Maldonado | last post by:
Hello list, The TCL trigger that uses NEW and OLD arrays failed after after I removed a unused column, now I got this error: pltcl: Cache lookup for attribute '........pg.dropped.24........' type 0 failed I already did a vacuum, but the error remain. Any idea how to fix/avoid that?
7
1835
by: eSolTec, Inc. 501(c)(3) | last post by:
Thank you in advance for any and all assistance. I have an application that pulls files, folders and registry keys of installed programs. I'm wanting to with a context menu selection of "Delete Selected", delete "ALL" of the checked selected files, folders, registry keys. Can someone show me some code to do this please?
3
1374
by: IraqiAli | last post by:
ok i have a couple of textboxes. The user is required to input values from 1 to 6 into those boxes. and submit it, those values would then go into an array. What i need to do is do checks to make sure that there are no invalid inputs. Ive dont a check to make sure no boxes are left empty and now i need to do a check to make sure the user doesnt input repeated values. basically they can enter 1, 2, 3, 4, 5, 6 they cant enter ...
13
2465
by: programming | last post by:
how do i delete from a text file 1 of the following lines: jon|scott adam|smith <--delete paul|clark say i would like to delete the middle line of this txt, in member.txt what php code or logic would help me accomplish this?
3
3755
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
One more for today.... As I add more and more lines to my RichTextBox the array that holds its strings gets bigger and bigger and the vertical scroll bar gets smaller and smaller until the string array finally runs out of memory. I'd like to set some line limit and once that limit is reached, start removing the first line each time a new line is appended onto the end. I think this is probably more of an array manipulation question than...
7
1680
by: bagelman | last post by:
Hi, I have a string Array. Its length is 100. I want to search the array to find repeated strings in it. And after finding repeated strings I want to write to screen which word repeated how many times.. I thought that 2 array is necessary (one for storing repeated word the other is for storing repetition number) for this. But I couldn't write the code. Please give me some hints about it. Thanks...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10090
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9949
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.