I am currently working on a JavaScript task that involves checking for the existence of a value in an array and then adding it to another array. Here is the setup:
const originalArray = ["apple", "banana", "cherry", "date", "elderberry"];
let newArray = [];
Below is a snippet of the code I have written:
let i = originalArray.length;
let j = 0;
do {
if(typeof originalArray[j] == 'a') {
console.value += "A doesn't exist.";
} else {
console.value += "A does exist."
}
j++;
} while (j < i);
For some reason, despite adjusting the value of i
, the code always outputs "A does exist.
". Can anyone help me identify where I might be going wrong?
Appreciate any insights!