I am learning javascript and really just started – I am using the Firebug Extension in Firefox to try out a few things.
I have set up 2 var(iables) and the 2nd one uses values from the first one:
var multipleValues = [10,20,30,40,50] ;
var reverse = multipleValues.reverse();`
Now I want to pull data from that array via an if statement and create an alert like so:
if (multipleValues [1] == 20) {
alert("Value is there.");
}
else {
alert("Value is not there");
}
Now here is my question – How come when I run the code like this it gives me the “else” option, but when I comment out the var reverse it comes up as correct?
I thought because I had declared the variable at the start I can access it later on, however using the reverse option seems to be canceling it out?? Am I misunderstanding the theory??
Cheers
The
reversemethod modifies the array in place (while also returning the array). Try something like this instead: