I'm trying to find if a value exists or not in an array and then add it to a third array. I am using JavaScript.
Here are my declarations:
var testArray1 = ["a", "b", "c", "d", "e"];
var testArray2 = [];
Here is my code snippet:
var x = testArray1.length;
var y = 0;
do {
if(typeof testArray1[y] == 'a') {
console.value += "A doesn't exist.";
}
else {
console.value += "A does exist."
}
y++;
while (y < x);
For some reason (even if I enter in (anything greater than 0)
instead of x
it always says A does exist.
Could anyone point me out where my code is wrong?
Thanks!