Javascript 函数中的IndexOf

Javascript 函数中的IndexOf,javascript,Javascript,如何返回此数组中指针的索引位置 函数findNeedlehaystack{ 返回findNeedle。针的索引; } findNeedle['3','123124234',未定义,'Pineer','world','hay',2','3',true,false] 成功 return haystack.indexOf('needle'); return haystack.indexOf('needle'); 您需要使用传递给函数的参数,而不是函数本身。findNeedle是函数,而不是作为函

如何返回此数组中指针的索引位置

函数findNeedlehaystack{ 返回findNeedle。针的索引; } findNeedle['3','123124234',未定义,'Pineer','world','hay',2','3',true,false] 成功

return haystack.indexOf('needle');
return haystack.indexOf('needle');
您需要使用传递给函数的参数,而不是函数本身。

findNeedle是函数,而不是作为函数参数传递的数组。在函数内部,haystack是您的数组

函数findNeedlehaystack{ 返回草垛。针的索引; } var result=findNeedle['3','123124234',未定义,'needle','world','hay',2','3',true,false];
console.logresult 您不应该在函数上运行method.indexOf。取而代之的是在你的房子里叫它干草堆