-2

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];)

2 Answers2

0

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);
}
EKW
  • 2,059
  • 14
  • 24
0

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]];
};
Jared Smith
  • 19,721
  • 5
  • 45
  • 83