is there a way to do this in javascript?
if('a' in array[index] or 'A' in array[index] ):
print(bArray[0], end = ' ')
(search array for a string, return index for that string, and then console.log(bArray[location];
)
is there a way to do this in javascript?
if('a' in array[index] or 'A' in array[index] ):
print(bArray[0], end = ' ')
(search array for a string, return index for that string, and then console.log(bArray[location];
)
Yes
// Convert the string to lower case so that it will match both 'a' and "A"
const aIndex = array[index].toLowerCase().indexOf('a');
if(aIndex !== -1) {
console.log(aIndex);
}
This is easiest to accomplish via regex match:
let match = s.match(/[a]/i);
if (match) console.log(match.index, match[0]);
If you want a more generic version:
let matcher = s => {
let regex = new RegExp(s, 'i');
let match = s.match(regex);
return match && [match.index, match[0]];
};