rome_castillo
10 years agoOccasional Contributor
Can I pass the object Property Name as a parameter
I have used FindAllChildren to get all the children of a window object and put it in an array (objArray). I am trying to pass the Property Name (myName) and Property Value (myValue) to find the index in the array where a match is found.
Here's part of the JScript code:
function getIndex(objArray, myName, myValue)
{
var i;
for(i=0; i<=objArray.length; i++)
{
if(objArray[i].myName == myValue)
....
{
....
}
This function is failing since it is looking for "myName" Property Name instead of the string that was passed (ie I was trying to pass "ClrClassName" to myName).
Is there a way to use pass the Property Name as a parameter for the above use?
Thanks!
function getIndex(objArray, myName, myValue) { for(var i = 0; i < objArray.length; i++){ if(objArray[i][myName] == myValue){ //do stuff
} { }