I have an array, and I want to find which element is there twice.
I thought of making a new array, for each element in the original array, without that element. This array contains the same elements, but after slicing the one we are dealing with. Then we'd try to find it in this new array: so if it exists twice in the original array, it'd be there and it would return "true", and if not, it would not be in the new array and it would return "false", based on my code.
let arr = ["stephanie", "alex", "steven", "alex"]
function double(name) {
arr.forEach((name, index) => {
let newarr = arr.slice(index);
console.log(newarr);
const searchedelement = newarr.find(name === nom);
console.log(searchedelement);
})
}
console.log(double(name))
doublefor you to log.