简体   繁体   中英

Javascript - How to combine seperate individual array to single array?

Let's say I have 2 individual arrays that consists of lat and long values respectively.

lat = [23,34,25];
long = [11,12,13];

My question is how do i create output of combined lat and long arrays above to:

combined_latlong = [ [23,11] , [32,12], [25,13] ];

You can use map()

 const lat = [23, 34, 25]; const long = [11, 12, 13]; const result = lat.map((l, i) => [l, long[i]]); console.log(result);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM