g(..).indexOf(item)

Returns the index at which the specified item exists in the Gimme Object's underlying array (returns -1 if the items is not found).

Returns: index at which the specified items exists, or -1 if the item does not exists in the Gimme Object's underlying array.
Params:
  • item, required: The item being sought from the Gimme Object's underlying array whose index is to be retrieved.

Examples:
// Use Gimme to search a normal array
var annaIndex = g(['Steve', 'Emily', 'Guinness', 'Anna', 'Madeline', 'Jonah', 'Gabriel']).indexOf('Anna');
alert('Anna was found at index: ' + annaIndex);


// Search a Gimme Object for a particular element
var steve = document.getElementById('steve');
var steveIndex = g('div.person').indexOf(steve)
alert('#steve was found at index: ' + steveIndex);


// What happens when an item is not found?
var someArray = [ 'abc', 'def', 'ghi', 'jkl', 'mno' ];
var xyzIndex = g(someArray).indexOf('xyz');
if (xyzIndex === -1)
{
	alert('"xyz" was not found');
}
else
{
	alert('"xyz" was found at index: ' + xyzIndex);
}

Last edited Nov 13, 2007 at 9:53 PM by sstchur, version 1

Comments

No comments yet.