On 17.9.2010, at 15.03, Richard Quadling wrote: > Hi. > > How do I do something like this (just an example) ... > > [1,2,3].each(function(val){return val * val;}); > > such that the result is ... > > [1,4,9]
[1,2,3].map(function(i){ return i * i }); // http://api.prototypejs.org/language/enumerable/prototype/collect/ Note that invoke is a shorthand for map except that it calls a method for each of the items: ['hello', 'world'].invoke('toUpperCase'); // http://api.prototypejs.org/language/enumerable/prototype/invoke/ // -> ['HELLO', 'WORLD'] Cheers, //jarkko -- Jarkko Laine http://jlaine.net http://dotherightthing.com http://odesign.fi Check out my latest book, Unobtrusive Prototype, fresh off the Peepcode oven: http://peepcode.com/products/unobtrusive-prototype-js -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.