Hi,
I have a string like this:
I'd like to get the value of one of the variables given the variable name. e.g. I need to know what the value of x is.Code:v=1|w=2|x=3|y=4|z=5
Here is the code I have so far:
This successfully alerts for each variable and value so I know it's almost working, but I need to just return the value of the variable passed into the function.Code://Call function getValue('x'); function getValue(variableIn){ var wholeString = 'v=1|w=2|x=3|y=4|z=5'; if(wholeString){ var stringArray = wholeString.split('|'); for(x in stringArray) { var stringItem = stringArray[x]; var arrayStringItem = stringItem.split('='); for (y in arrayStringItem) { alert(arrayStringItem[y]); } } }else{ return(0); } }
Can someone show me how to do this?
Thanks folks...




Bookmarks