Convert Arrays to objects - Javascript Array Operation

Javascript examples for Array Operation:Array Convert

Description

Convert Arrays to objects

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(){/*  www .j  av  a 2  s.co m*/
function firstAndLast(a, o){
    return !(o = o || {}, o[a.shift()] = a.pop()) || o;
}
console.log(firstAndLast([1,2,3,4,5]));
console.log(firstAndLast(['a','to','z']));
console.log(firstAndLast(['a','to','z'], {a:'nother',obj:'ect'}));
    }

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

Related Tutorials