Hello, I've been helped with the prototype below by blemmo (thanks). It allows me to search my array using one property == a value. Now, I'd like to use it to: if ((prop1 == val1) &&(prop2 == val2) && (prop3 == val3) { // search array for all values in array with the values of val1, val2 and val3 }; Also, a way to search if one of the prop and val's are blank, ie... ((prop1 == val1) &&(prop2 == val2) && (prop3 == val3) where prop2 and val2 are "undefined" so the search will only search for the prop and val that are not "undefined" make since? Don't know where to start. help and thanks in advance. Array.prototype.id = function(prop, val) { var res:Array = new Array(); var i = this.length; while (i--) { if (this[i][prop] == val) { res.push(this[i]); } else { } } return (res); };
try the following which returns the index of the element whose properties match your values: Array.prototype.id = function(prop1, val1, prop2, val2, prop3, val3) { var res:Array = new Array(); var i = this.length; while (i--) { if (this[i][prop1] == val1 && this[i][prop2] == val2 && this[i][prop3] == val3) { res.push(i); } else { } } return (res); };
thanks Kglad but it's not working for me. I thought to do that and tried it already but it seems to not pull up any info from my array and place them into the respective dynamic text boxes. I just places, "undefined" in all. though when I use the original code it works fine. I'm not sure why. I believe I've done everything correct. I'll try to keep hammering it out, believing I was on the correct coding path. thanks again, sky
it is an array like this.. but with more properties... also, is it better to use XML to load large arrays or is it ok to use actionscript in the file. which is faster to load? say if I had an array of 150 elements? myArray = [{myname:"bob", county:"skagit", city:"Sedro Woolley", id:1, pic:"1.jpg",pic1:"2.jpg",pic2:"3.jpg",pic3:"4.jpg"}, {myname:"bob", county:"skagit", city:"Sedro Woolley", id:1, pic:"1.jpg",pic1:"2.jpg",pic2:"3.jpg",pic3:"4.jpg"
then everything should work. are you using strings for the parameters passed to id()???
Don't see what you're looking for? Try a search.
|