javascript 函数 inArray [英] javascript function inArray
本文介绍了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()
http://www.w3schools.com/jsref/jsref_indexof_array.asp
这篇关于javascript 函数 inArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文