On Jan 10, 2006, at 6:52 PM, sergio wrote:
looking to do something like this, but i am not sure if there is
anything like it in javascript.. it does seem pretty mochikit-ish..
var array = new Array (dog, cat, hamster, horse, monkey);
positionAnimal(hamster) = 2; <- this type of functionality..
if value exists in the array, return the index, otherwise, returns
something else..
It doesn't currently exist in MochiKit. What you would want is
something like this (written in just plain javascript):
var find = function (lst, value, start/* = 0 */, /* optional */end) {
if (typeof(end) == "undefined" || end == null) {
end = lst.length;
}
for (var i = (start || 0); i < end; i++) {
if (lst[i] == value) {
return i;
}
}
return -1;
};
I'll go ahead and make sure this gets into MochiKit 1.2.
-bob