I have made a code in JavaScript to concatenate two arrays of names and sort them out without duplicate. When it shows on the screen I don't see the item 0 of my new array. I don't know why, in the console.log I see the item 0 which is "Alice". But, what I actually see on the webpage is 1. William, 2. Beatrice, 3. Charlie, 4. Charlotte, etc.
let nameM = [
"William",
"Nathan",
"Raphael",
"Sam",
"Emile",
"Leo",
"Pascal",
"Felix"
];
let nameF = [
"Charlotte",
"Sam",
"Emma",
"Charlie",
"Emilie",
"Pascal",
"Lea",
"Beatrice",
"Alice"
];
let name, list;
name = [];
function newArray(nameM, nameF) {
nameM.concat(nameF).forEach(item => {
if (name.indexOf(item) === -1)
name.push(item);
});
return name;
}
console.log(newArray(nameM, nameF));
list = "<ol>";
name.forEach(firstName);
list += "</ol>";
document.getElementById("firstNames").innerHTML = list;
function firstName(values) {
name.sort();
list += "<li>" + values + "</li>";
}