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

String matching in an array



I am working on a search engine where all of the
html code is inside arrays which are outputted given
some case (say - output all urls in the "widget" category)
where I have specified a "link" object

function makeLink() {
	this.Date="";
	this.Category="";
	this.URL ="";
	this.Name = "";
	this.Description ="";
	return this;
}

and then create an array of links.
What I can't seem to do though is "search"
down the array to find if a given link object has
a given Description value.
below is the code I have currently - which works to display
this html
start code line------------------------------
----------------------------------------------
<script language="javascript">
	var key = "";

	function makeEntry (){
		this.Date = "";
		this.Name="";
		this.URL = "";
		this.Desc = "";
		this.Category = "";
		return this;
	}

	function makeArray(n) {
		this.length = n;
		for (var k = 1; k <= n; k++) {
				this[k] = "";
		}
		return this;
		}		

		function makeLinks(size) {
				this.length = size;
				for (var r=1; r<= size; r++) {
							this[r] = new makeEntry();
							this[r].Date = datesArray[r];
							this[r].Name = namesArray[r];
							this[r].URL = urlsArray[r];
							}
					return this;
			}
linksize = 4;

datesArray = new makeArray(linksize);
datesArray[1] = "(Jan.1.96)";
datesArray[2] = "(Feb.5.96)";
datesArray[3] = "(Feb.11.96)";
datesArray[4] = "(Mar.1.95)";

namesArray = new makeArray(linksize);
namesArray[1] = "Yahoo";
namesArray[2] = "Netscape";
namesArray[3] = "Andrew's";
namesArray[4] = "Another anonymous link";

urlsArray = new makeArray(linksize);
urlsArray[1] = "http://www.yahoo.com";;
urlsArray[2] = "http://www.netscape.com";;
urlsArray[3] = "http://www.c2.org/~andreww/javascript";;
urlsArray[4] = "http://www.foo.bar/baz/";;

		function showall(linkobj) {
				for (var s=1; s<= linkobj.length; s++) {
					document.write("number" + 
s +" -----<p>");
						
document.write(linkobj[s].Date + " -- " +"<a href="+linkobj[s].URL+" window.status=" +linkobj[s].name+">" + linkobj[s].Name +"</a>" );
						document.write("-----<p>");
				}
			}

		


jsi = new makeLinks(datesArray.length);
showall(jsi);

document.write("<p>");



</script>

---------------------------------
This gives me the construct I want, but I dont know how to 
parse down the array and "ask" each link if it has a date of "(Jan.5.96)"
or if its catagory is "general"  etc.  Any help would be
appreciated.  The above is unique in that it shows how
to have an array of arrays...... and how to reference them as well.

Sorry about the word wrap off the screen - this code does work so
if you get errors email me and Ill send you a non-wrapped version..


-------------------------------------------
Andrew Wooldridge (andreww@c2.org)        |
http://www.best.com/~wooldri/             |
http://www.c2.org/~andreww/javascript/    |
-------------------------------------------