»
EnglishFrenchVietnamese

Print - Multi-Dimensional Array Searching - JavaScriptBank.com

Full version: jsB@nk » Snippet » Multi-Dimensional Array Searching
URL: https://www.javascriptbank.com/multi-dimensional-array-searching.html

Multi-Dimensional Array Searching © JavaScriptBank.comUse this prototype function to search through a multi-dimensional array. Simple yet efficient! Includes examples.

Full version: jsB@nk » Snippet » Multi-Dimensional Array Searching
URL: https://www.javascriptbank.com/multi-dimensional-array-searching.html



JavaScript
<script language="javascript">// Created by: Jonathan Fenocchi :: http://www.slightlyremarkable.com///  Search format://  ArraytoSearch.search (String search term [, Boolean exact match])////  Note: "ArraytoSearch" is an array variable. String search term is what//  you want to find in that array. Boolean exact match can be set to true//  or false. If you want to find an exact match, you can omit this argument//  or send it as false. If you want to find an instance, you can send//  this argument as true.////  Example: http://www.webdeveloper.com/forum/showpost.php?p=348195&postcount=22//Array.prototype.search = function(s,q){  var len = this.length;  for(var i=0; i<len; i++){    if(this[i].constructor == Array){      if(this[i].search(s,q)){        return true;        break;      }     } else {       if(q){         if(this[i].indexOf(s) != -1){           return true;           break;         }      } else {        if(this[i]==s){          return true;          break;        }      }    }  }  return false;}</script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->