JSFiddle - React, Tailwind, and code Playground
by Brock Whittaker
JavaScript
array = ["ability", "abilities", "abilitys"];
function getnthLetter(word, letter) {
asciiLetter = word.charCodeAt(letter - 1);
}
function createArrayJSON(array) {
firstLetter = {};
for (x = 0; x < array.length; x++) {
getnthLetter(array[x], 1);
Letter1 = asciiLetter;
if (array[x].length > 1) {
getnthLetter(array[x], 2);
Letter2 = asciiLetter;
} else {
Letter2 = 0;
}
if (typeof firstLetter[Letter1] === 'undefined') {
firstLetter[Letter1] = [];
}
if (typeof firstLetter[Letter1][Letter2] === 'undefined') {
firstLetter[Letter1][Letter2] = [];
}
firstLetter[Letter1][Letter2].push(array[x]);
}
document.write(JSON.stringify(firstLetter));
}
createArrayJSON(array);