Javascript examples for Array Operation:Array Convert
Convert Arrays to objects
<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>