Array split at index - Javascript Array Operation

Javascript examples for Array Operation:Array Index

Description

Array split at index

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(){/* w  w w . j a  v  a  2  s.  c om*/

var arr = ['Number 1', 'name', 'Number 2', 'name'],res ="";
for(var i=0,len=arr.length;i<len;i+=2){
   res += arr[i] + ":" + arr[i+1] + ((i+2 != len) ? "," : "");
}
console.log(res);


    }

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

Related Tutorials