Re: Array manipulation question
- From: DL <tatata9999@xxxxxxxxx>
- Date: Fri, 30 May 2008 14:12:12 -0700 (PDT)
On May 30, 9:24 am, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@xxxxxxxxxxxxxxxx> wrote:
Hi,
Well, they do not contain a 'set' but just a plain value.
// say, the business rule is, if all set of data are of same value ( 0
|| 1), then do nothing
else alert ('hey dark sheep found').
I understand Array has a bunch of methods, but not sure which one is a
good one to solve the above problem.
No offense, but this is so basic I advise you to buy a book on
JavaScript (any will do, but O'Reilly's Definitive Guide is good).
Here follows an example to get you going.
(It can be written in many different ways, and shorter, but I hope this
version is clear to you.)
<script type="text/javascript">
var myArray = [];
// populate it
myArray[0] = 0;
myArray[1] = 1;
myArray[2] = 0;
myArray[3] = 0;
var arrLength = myArray.length;
var firstVal = myArray[0];
for(var i=0;i<arrLength;i++){
if (myArray[i] != firstVal){
alert ("Black sheep found.");
break;
}}
</script>
Thanks.
You're welcome.
Regards,
Erwin Moller
No offense at all, I know it's embrassing and thanks for the book
recommendation.
.
- References:
- Array manipulation question
- From: DL
- Re: Array manipulation question
- From: Erwin Moller
- Array manipulation question
- Prev by Date: Re: clip board data as html
- Next by Date: Re: javascript programming idiom
- Previous by thread: Re: Array manipulation question
- Next by thread: Re: Array manipulation question
- Index(es):
Relevant Pages
|