Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within HTML Pages with CSS and JavaScript
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
HTML Pages with CSS and JavaScript
Checking for unique values in an array
Madhusudhan GoturKaranam
Greenhorn
Posts: 4
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
I have an array which can have dynamic values..Don't know count..
I have to check for uniqueness in that array..
For Example, Array A1 = [1,2,3,3,1]
Here, '3' and '1' is repeated. I should for unique values and giving message if its repeated.
Pls help me..
Eric Pascarello
author
Posts: 15385
6
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Basically you need to make a second array. Using the number of the firxt array, you add one too it. You need to loop through the whole array.
count[Array1[i]]
use the length property to check the number of elements.
No I am not going to code it!
Yuriy Fuksenko
Ranch Hand
Posts: 413
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Here is an idea - since you could use the numbers you going to store as array indexes.
so,
var myArray = new Array(); function addToArray(number){ if(myArray[number] && myArray[number]!=null) { alert("number already exist"); } else{ myArray[number]=1; } }
than you could use
for(var i in myArray){ ... }
to loop through array.
Or, you coul have 2 arrays - one for indexes and one for data
var indexes = new Array(); var myArray = new Array(); function addToArray(number){ if(indexes[number] && indexes[number]!=null) { alert("number already exist"); } else{ indexes[number]=1; myArray[myArray.length]=number; } }
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
help me with array
Finding top 3 repeated numbers in an array
Deleting repeated values in an array
Set and Map
Comparing Integers in Array
More...