IndexOf: Difference between revisions
Jump to navigation
Jump to search
Created page with "IndexOf(''var'', ''item'') == Description == The IndexOf() method returns the position of ''item'' in ''var''. ''item'' can be a string or an array. The result returned star..." |
|||
Line 7: | Line 7: | ||
== Example (Basic) == | == Example (Basic) == | ||
Find an item: | |||
<pre> | <pre> | ||
a=[1,2,3,4,5] | a=[1,2,3,4,5] |
Revision as of 22:04, 4 February 2014
IndexOf(var, item)
Description
The IndexOf() method returns the position of item in var. item can be a string or an array. The result returned starts with 0. If item is not found, -1 is returned.
Example (Basic)
Find an item:
a=[1,2,3,4,5] Print IndexOf(a,3) Print IndexOf("abcde","c") Print IndexOf(a,9)
The result will be:
2 2 -1
Example (JavaScript)
Add an item to the end.
var a=[1,2,3,4,5]; NSB.Print( a.indexOf(3) ) NSB.Print( "abcde".indexOf("c") ) NSB.Print( a.indexOf(9) )
The result will be:
2 2 -1