Get the first and last item in an Array - JS

后端 未结 6 1589
面向向阳花
面向向阳花 2021-01-18 03:01

I am trying to get the first and last item in array and display them in an object.

What i did is that I use the first and last function and then assign the first ite

6条回答
  •  囚心锁ツ
    2021-01-18 03:34

    ES6

    var objOutput = { [myArray[0]]: [...myArray].pop() }
    

    var myArray = ['Rodel', 'Mike', 'Ronnie', 'Betus'];
    
    var objOutput = { [myArray[0]]: [...myArray].pop() }
    
    console.log(objOutput);

提交回复
热议问题