merge 2 arrays in 1 array and read both array values – javascript

array1 = [5, 10, 20];

array2 = [10, 20, 30];

 

var result = [];

for(var i=0;i<array1.length;i++){

result.push({a:array1[i],b:array2[i]});//add object literal

}

 

console.log(result[0].a);

console.log(result[1].b);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s