JSFiddle - React, Tailwind, and code Playground
JavaScript
var firstUniqChar = function(s) {
s = s.split('');
let t = [], index = 0;
for (let i = 0; i < s.length; i++) {
if (!t.includes(s[i])) {
let el = s.splice(i, 1, null)[0];
if (!s.includes(el)) {
return index;
} else {
t.push(el);
}
}
index++;
}
return -1;
};
s = "loveleetcode";
console.log(firstUniqChar(s));