What goes in the blank?
// returns the index of "x", or -1 if not present
function locate(arr, x) {
return arr.____(x);
}
// locate(["a","x"], "x") -> 1
Answer: indexOf
indexOf() returns the matching index or -1.
Play Problem Solving ▸
// returns the index of "x", or -1 if not present
function locate(arr, x) {
return arr.____(x);
}
// locate(["a","x"], "x") -> 1
Answer: indexOf