Send array with GET Request by appending array to URL - Javascript String Operation

Javascript examples for String Operation:String Format

Description

Send array with GET Request by appending array to URL

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from   w w w  . j  a v  a 2  s. co m*/
var a=['one', 'two'];
var url = 'www.google.com';
for (var i=0; i<a.length; ++i) {
    if (url.indexOf('?') === -1) {
        url = url + '?array[]=' + a[i];
    }else {
        url = url + '&array[]=' + a[i];
    }
}
console.log(url);
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials