From: Thomas 'PointedEars' Lahn on 15 Jan 2010 13:41 Garrett Smith wrote: > Thomas 'PointedEars' Lahn wrote: >> Garrett Smith wrote: >>> var imgArray = library.map(filterByName("img")); >>> var captionArray = library.map(filterByName("caption")); >>> [...] >>> >>> Where not supported, Array.prototype.map functionality can be added, as >>> indicated on MDC page[1]. >> >> What a waste. If an Array prototype method should be used here, then >> Array.prototype.forEach(). > > Array.prototype.forEach calls a supplied function on each element in the > Array. It does not create a new Array. You don't say. > Array.prototype.map creates a new array with the results of calling a > supplied function on each element in the array. Exactly. If you use Array.prototype.map() you have to iterate *twice* (at least internally) on the *same* array to get the two resulting arrays. That's the waste. var imgArray = [], captionArray = []; library.forEach(function(e, i, a) { imgArray[i] = e.img; captionArray[i] = e.caption; }); PointedEars -- realism: HTML 4.01 Strict evangelism: XHTML 1.0 Strict madness: XHTML 1.1 as application/xhtml+xml -- Bjoern Hoehrmann
From: Jorge on 15 Jan 2010 13:52 On Jan 15, 7:41 pm, Thomas 'PointedEars' Lahn <PointedE...(a)web.de> wrote: > > var > imgArray = [], > captionArray = []; > > library.forEach(function(e, i, a) { > imgArray[i] = e.img; > captionArray[i] = e.caption; > }); e is undefined... -- Jorge.
From: Thomas 'PointedEars' Lahn on 15 Jan 2010 14:00 Jorge wrote: > Thomas 'PointedEars' Lahn wrote: >> var >> imgArray = [], >> captionArray = []; >> >> library.forEach(function(e, i, a) { >> imgArray[i] = e.img; >> captionArray[i] = e.caption; >> }); > > e is undefined... Where? PointedEars -- Anyone who slaps a 'this page is best viewed with Browser X' label on a Web page appears to be yearning for the bad old days, before the Web, when you had very little chance of reading a document written on another computer, another word processor, or another network. -- Tim Berners-Lee
From: Jorge on 15 Jan 2010 14:27 On Jan 15, 8:00 pm, Thomas 'PointedEars' Lahn <PointedE...(a)web.de> wrote: > Jorge wrote: > > Thomas 'PointedEars' Lahn wrote: > >> var > >> imgArray = [], > >> captionArray = []; > > >> library.forEach(function(e, i, a) { > >> imgArray[i] = e.img; > >> captionArray[i] = e.caption; > >> }); > > > e is undefined... > > Where? And 'a' is unused... -- Jorge.
From: Thomas 'PointedEars' Lahn on 15 Jan 2010 14:39
Jorge wrote: > Thomas 'PointedEars' Lahn wrote: >> Jorge wrote: >> > Thomas 'PointedEars' Lahn wrote: >> >> var >> >> imgArray = [], >> >> captionArray = []; >> >> >> >> library.forEach(function(e, i, a) { >> >> imgArray[i] = e.img; >> >> captionArray[i] = e.caption; >> >> }); >> >> > e is undefined... >> >> Where? > > And 'a' is unused... Yes, that argument does not need to be named here; however, the purpose here was to show how forEach() could be used -- `a' is a reference to the array.¹ You have not answered my question, though. I take it then that you found out you were wrong. PointedEars ___________ ¹ <https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/forEach> -- Use any version of Microsoft Frontpage to create your site. (This won't prevent people from viewing your source, but no one will want to steal it.) -- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.) |