473,387 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Deleting repeated values in array

12
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 2241
acoder
16,027 Expert Mod 8TB
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 Expert Mod 8TB
See this post. You'll have to adapt it - it was for a specific question.
Apr 18 '07 #3
mrhoo
428 256MB
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.unique(); or someArray=someArray.unique()
Apr 18 '07 #4

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

Similar topics

10
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...
18
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 ...
7
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
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........'...
7
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...
3
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...
13
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...
3
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...
7
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.