Iteration Push Alternative Javascript

Alexey Ayzin

Obviously, this is not allowed in javascript:

for (var i=0; i<data.length; i++){
    array[i].push(data[i].name);
}

Does anyone know of a workaround that does the same thing?

Maantje

You can do

for (var i=0; i<data.length; i++){
    array[i] = [];
    array[i].push(data[i].name);
}

https://jsfiddle.net/zv0xfzzs/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

HotTag

Archive