If in a Array
, I look for an element with includes
, instead of returning a boolean, how can I return the match, that is, what was the element found ?
var a = ["eeuu","usa"];
var b = "eeuu";
var c = a.includes(b);
console.log(c);
If in a Array
, I look for an element with includes
, instead of returning a boolean, how can I return the match, that is, what was the element found ?
var a = ["eeuu","usa"];
var b = "eeuu";
var c = a.includes(b);
console.log(c);
You can use
indexOf
instead ofincludes
to get the index of the searched element within the array:You can use:
Complete code with a function: