let friends = ["Ahmed", "Sayed", "Ali", 1, 2, "Mahmoud", "Amany"];
let index = 0;
let counter = 0;
// Output
"1 => Sayed"
"2 => Mahmoud"
while (index < friends.length) {
index++
if (typeof friends[index] === "number") {
continue;
}
if (friends[index].startsWith(friends[counter][counter])) {
continue;
}
console.log(friends[index])
}
And i Expect to get this output.
"1 => Sayed" "2 => Mahmoud"
but console gave me this error Uncaught TypeError: Cannot read properties of undefined (reading 'startsWith')