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
With ES6 and destructuring:
const myArray = ['Rodel', 'Mike', 'Ronnie', 'Betus']; const { 0: first, length, [length -1]: last } = myArray //getting first and last el from array const obj = { first, last } console.log(obj) // { first: "Rodel", last: "Betus" }