HasIndex

From MiniScript Wiki
Jump to navigation Jump to search

hasIndex return whether the given index is valid for this object, that is, whether it could be used with square brackets to get some value from self.

See also: Indexes

Arguments

Parameter Name Default Value Meaning
self string, list, or map object to check for an index on
index any value to consider for possible index

Usage Notes

When self is a list or string, the result is true for integers from -(length of string) to (length of string-1). When self is a map, it is true for any key (index) in the map. If called on a number, this method throws a runtime exception.

Example

"foo".hasIndex(2)	// returns 1
"foo".hasIndex(3)	// returns 0