I have an array of strings, and I'm trying to define a function where imputing string "xyz" will search the array and return the index. "xyz" will be different each time the function is called.
I have tried this (JavaScript):
var data = ["abc","def","ghi","jkl","mno"];
\\ this array is actually much longer
look = function(a){return a = this;}
\\ at first I was trying data.findIndex("xyz")
\\ but Chrome Dev. tools said "xyz" is not a function
Params = function(x="abc"){
y = data.findIndex(look,x);
return y;
}
\\ Params("abc") should return 0
\\ Params("def") should return 1
\\ Params("ghi") should return 2
\\ etc.
I know I could do this with a for-loop, and cycle through all of the values in "data" but this seems inefficient. Is there a better way? Am I misunderstanding the "findIndex" method?