Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Rolf Niepraschk Newsgroups: comp.lang.javascript Subject: Iterating through an array (special syntax) Date: Tue, 17 Oct 2017 12:39:12 +0200 Lines: 35 Message-ID: Reply-To: Rolf.Niepraschk@gmx.de Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net DTeqqdx7gm1kHUVX7RlPAgUuPrv7IsQB0vSbiFbqvrCcQ6XdnH Cancel-Lock: sha1:jqgeX8tmBWd7rfcAVTHKyIXaFZc= X-Mozilla-News-Host: news://news.individual.de:119 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 Content-Language: en-US Xref: csiph.com comp.lang.javascript:34118 Hello, I search for a function with the following characteristics: -------------------------- function foo(arr) { /* unknown implementation */ } Call: foo([1,2,3,4]) .each(function(oldItem, newItem) { console.log('old: ' + oldItem + ' ' + 'new: ' + newItem); // should be: // old: 1 new: 2 // old: 2 new: 4 // old: 3 new: 6 // old: 4 new: 8 }) .done(function(result) { console.log('Result: ' + result);// should be: [2,4,6,8] } -------------------------- The names "each" and "done" are not important. The static array is an example. In reality the array is the result of a network request inside of the function. What would be the best implementation? Thanks in advance. ...Rolf