This is my code
function nameIsDuplicate(name){
objects = $("#content").find('p.itemOldName');
$(objects).each(function(i, object){
console.log("*"+($(object).text()).toLowerCase() + "*" + name.toLowerCase()+"*");
if(($(object).text()).toLowerCase() == name.toLowerCase())
return true;
});
return false;
}
I am building an online file manager system.
the name argument is a name provided by the user via a textbox, and the $(object).text() is the name of files and folders in the current directory. These names come via exec("ls") command.
I need to check if the name provided by the user already exists. So I compare the name with every files/folders name. The problem is it doesn't find duplicates. The result of the above code is given in the following image

()around$(object).text(), you sure that is needed?.trim()to clear them. Also to check instead of logging value, log their lengths