I have a myArray = [A,C,D,G,J,L,P]
and a myString = "ABCDEF"
I want to create a new array, containing only the characters of myString which can also be found in myArray, so that myOtherArray = [A,C,D]
I think the code should look something like this, but its not working yet.
for (int i=0; i<myString.length(); i++) {
for (int j=0; j<myArray.length(); j++) {
if ((myString.charAt(i)) == myArray[j]) {
myOtherArray.push(myArray[j])
}
}
}
If you try to run it in the console of your browser (or just check the error log), you will see that
int i=0is wrong andlengthis not a function. Replaceintwithvar(both) andlength()withlength(both), and it works.