javascript函数inArray [英] javascript function inArray

查看:104
本文介绍了javascript函数inArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个JavaScript函数,可以在一个字符串数组,并返回true,如果该字符串数组中。

I need a javascript function that can take in a string and an array, and return true if that string is in the array..

 function inArray(str, arr){
   ...
 }

警告:不能使用任何JavaScript框架

caveat: it can't use any javascript frameworks.

推荐答案

您可以使用arr.indexOf()

you can use arr.indexOf()

<一个href=\"http://www.w3schools.com/jsref/jsref_indexof_array.asp\">http://www.w3schools.com/jsref/jsref_indexof_array.asp

这篇关于javascript函数inArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆