Home
> InDesign Scripts > Search inside array
Search inside array
With this script we can search inside Array. This is not quite InDesign snippet and can be used in every Javascript. I really like approach to search problem, and want to share it with you. Script is not mine, I just found it on web long time ago.
Array.prototype.exists = function(search){ for (var i=0; i<this.length; i++) if (this[i] == search) return true; return false; } var myA = Array("yes","no","today","monday"); alert(myA.exists("yes")); // true alert(myA.exists("maybe")); // false
So, first five lines are function for searching. The prototype property allows you to add properties and methods to an object. Now, when we call ArrayName.exists(“some string”) search function will go through array and try to find match. If the match is function will return true, or if not, then false. We create sample Array called myA, and test it with last two lines.
Categories: InDesign Scripts
Javascript
Comments (0)
Trackbacks (2)
Leave a comment
Trackback
-
August 4, 2010 at 15:51Get Font Styles from Font Family « InDesign Snippets
-
June 1, 2011 at 14:28Get Font Styles from Font Family « tomaxxi.com