Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] Arrays


  • From: javascript@xxxxxxxxxx (Harry Love)
  • Subject: [Javascript] Arrays
  • Date: Wed, 21 Aug 2002 14:57:25 -0700

<snip>
-----Original Message-----
From: javascript-admin@xxxxxxxxxx [mailto:javascript-admin@xxxxxxxxxx]
On Behalf Of Bill Marriott
Sent: Wednesday, August 21, 2002 5:32 AM
To: javascript@xxxxxxxxxx
Subject: [Javascript] Arrays


Hi Everyone,

I am having trouble finding a way to work through a 2 member array and
search for rows that have identical values.

MyArray [0][0] = 2000,  MyArray [0][1] = "t"
MyArray [1][0] = 2000,  MyArray [1][1] = "f"
MyArray [2][0] = 2001,  MyArray [2][1] = "t"
MyArray [3][0] = 2001,  MyArray [3][1] = "t"

I want to find out that rows 3 and 4 in the above array have identical
values.
---------------------------
</snip>

Bill, I'm not sure if this is what you're looking for:

<script type="text/javascript">
var myArray = new Array(
	["2000","t"],
	["2000","f"],
	["2001","t"],
	["2001","t"]);
	
function compareValues()
{
	var x;
	for(x=0;x<myArray.length;x++)
	{
		var y;
		var z = x+1;
		var value1 = myArray[x].toString();
		for(y=z;y<myArray.length;y++)
		{
			var value2 = myArray[y].toString();
			if(value1 == value2)
			{
				//Execute your code here
				alert("myArray["+x+"] ("+value1+") =
myArray["+y+"] ("+value2+")");
			}
		}
	}
}
</script>


HTH,
Harry