Как определить позицию буквы в алфавите?

Даны буквы A, b, c, e. Как определить их позиции в алфавите?

Например, надо получить вместо a, b, c, e - 1, 2, 3, 5.


Ответы (3 шт):

Автор решения: Zhihar

например так:

const alphabet = "абвгд";
const index = alphabet.indexOf('в');

if (index != -1)
    console.log(index + 1);
else
    console.log('не найдено');
→ Ссылка
Автор решения: Aziz Umarov

Как-то так?

const alphabet = [ 'd', 'Y', 'A', 'b', 'c' , 'e', 'a']; 
const text = ['a','b','c','e'];

const result = text.map(item => alphabet.indexOf(item));

console.log(result);

→ Ссылка
Автор решения: Дмытрык

const arr = ['a', 'b','z', 'p'];
console.log(arr.map(letter => letter.charCodeAt(0) - 96))

→ Ссылка