Merging Multiple Arrays Evenly/Alternating with Javascript and Google AppScript -


i'm trying merge multiple arrays evenly/alternating in javascript/google appscript. there several arrays (5 or 6). i've tried 2 different methods, neither worked. don't work lot javascript , i've managed code point, can't merge properly; , of them said merging 2 arrays 1 (might problem).

i've seen plenty on php examples on how , pretty straight forward in logic reading , understand them better, javascript methods i've looked @ , tried far have failed produce results want. i'm not sure if it's way appscript formatting arrays or they're no made handle more 2.

my data looks similar @ moment:

var title = ["sometitle1","sometitle2","sometitle3"]; var link = ["somelink1","somelink2","somelink3"]; var date = ["somedate1","somedate2","somedate3"]; var data = ["somedata1","somedata2","somedata3"]; var = [title,link,date,data]; var mix = []; 

note: variable data will/should same length since data being pulled spreadsheet.

my desired output is:

mix = ["sometitle1","somelink1","somedate1","somedata1","sometitle2","somelink2","somedate2","somedata2","sometitle3","somelink3","somedate3","somedata3"]; 

i tried using appscript merge them this: return contentservice.createtextoutput(title + link + data + date), didn't work out properly, printed them in order instead of merging way i'd them too.

then tried using loop merge found here on sstackoverflow:

for (var = 0; all.length !== 0; i++) {     var j = 0;     while (j < all.length) {         if (i >= all[j].length) {             all.splice(j, 1);         } else {             mix.push(all[j][i]);             j += 1;         }     } } 

but splice merges every letter comma

mix = [s,o,m,e,t,i,t,l,e,1,s,o,m,e,t,i,t,l,e,2,s,o,m,e,t,i,t,l,e,3,s,o,m,e,l,i,n,k,1,...] 

and doesn't alternate data either.

the code (2 version) i'm working on is: here output & here output

(also, dumb question, use title[i] + \n or title[i] + "\n" adding new lines?)

use for loop , push() method :

function test(){   var title = ["sometitle1","sometitle2","sometitle3"];   var link = ["somelink1","somelink2","somelink3"];   var date = ["somedate1","somedate2","somedate3"];   var data = ["somedata1","somedata2","somedata3"];   //var = [title,link,date,data];   var mix = [];   for(var n=0;n<title.length;n++){     mix.push(title[n],link[n],date[n],data[n]);   }   logger.log(json.stringify(mix)); } 

enter image description here

and : title[i] + "\n" adding new lines


edit following comments :

your code should end :

  ...   for(var n=0;n<titles.length;n++){     mix.push(titles[n],links[n],descriptions[n],pubdates[n],authors[n]);   }   var mixstring = mix.join('');// convert array string without separator or choose separator want changing argument.    //print data , set mimetype   return contentservice.createtextoutput(mixstring)   .setmimetype(contentservice.mimetype.rss); } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -