forEach array javascript incomplete -



forEach array javascript incomplete -

updated

i trying build array calling callback function , feeding values other arrays. however, few values , cannot understand why.

the construction like:

var sorteddata = []; arrayprovidingthevalues.foreach(pushel,sorteddata);

and callback function is

function pushel(element,index) { console.log("pushel called"); this[index] = element; }

input:

saisinearray = {obj1, obj2 obj3, obj4, obj5, obj6}; contratarray = {obj21, obj22 obj23, obj24, obj25, obj26}; intervalnb = 5;

expected output

sorteddata = {obj1, obj2 obj3, obj4, obj5, obj6,obj21, obj22 obj23, obj24, obj25,obj6,obj26};

ps: detailled code show in more detail.

for (var k = 0; k < intervalnb; k++) { if (k * interval >= saisinearray.length) { } else if ((k + 1) * interval >= saisinearray.length) { saisinearray.slice(k * interval, saisinearray.length).foreach(pushel, sorteddata); } else { saisinearray.slice(k * interval, (k + 1) * interval).foreach(pushel, sorteddata); } if (k * interval >= contratarray.length) { } else if ((k + 1) * interval >= contratarray.length) { contratarray.slice(k * interval, contratarray.length).foreach(pushel, sorteddata); } else { contratarray.slice(k * interval, (k + 1) * interval).foreach(pushel, sorteddata); } }

instead of this[index] = element; seek this.push(element);

what you're doing on every execution of foreach(pushel) overwriting sorteddata array starting index 0.

javascript

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -