javascript function inArray

前端 未结 5 1700
南方客
南方客 2020-11-28 13:52

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){
   ...
 }
         


        
5条回答
  •  一个人的身影
    2020-11-28 14:33

    You could just make an array prototype function ala:

    Array.prototype.hasValue = function(value) {
      var i;
      for (i=0; i

    Note the use of '===' instead of '==' you could change that if you need less specific matching... Otherwise [3].hasValue('3') will return false.

提交回复
热议问题