What's a Jelo Shot? How do I use these tutorials?
Tutorial: Array Methods
Jelo.each
/* * Jelo.each iterates over Arrays and objects. If the function * passed to Jelo.each returns false, Jelo.each immediately stops * and returns the index it stopped at. */ // define an array var names = [ 'John', 'Jim', 'Mary', 'Jane' ]; // define an object var Landmark = { name : 'Eiffel Tower', latitude : 48.858001709, longitude : 2.29460000992 }; // output all names Jelo.each(names, function() { alert(this); // "this" == arguments[0] }); // output the first name that does NOT begin with "J" var notJ = Jelo.each(names, function(item, index) { return (this[0] == "J"); }); alert(names[notJ] + ' does NOT begin with "J".'); // notJ == 2 // output all info about our Landmark Jelo.each(Landmark, function(item, index) { alert(index + ': ' + item); });
Run the Jelo Shot above by clicking the orange icon.
See Jelo API for complete details.
Randomizing an Array Using shuffle()
// Array.sort() is built-in, Array.shuffle() is added by Jelo
var myArray = ['the', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog'];
// alphabetical order
myArray.sort();
$('.example').innerHTML = myArray.toString();
// random order (changes every time you run this jelo shot)
myArray.shuffle();
$('.example').innerHTML = myArray.toString();
Run the Jelo Shot above by clicking the orange icon.
See Jelo API for complete details.
