I have a function that correctly searches within an array and returns the match, but it is case sensitive. I need the comparison to be done at both ends in lowercase so it doesn't distinguish.
How can I do it?
This is my current code:
function buscar(mi_array, valor, pos){
var results = mi_array.filter(function (mi_array) { return mi_array[pos].startsWith(valor); });
var firstObj = (results.length > 0) ? results[0] : null;
return results;
}
For these cases, it is highly recommended and it is a good practice, when comparing strings, to "convert" all to uppercase or all to lowercase .