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
Do like this :-
var myArray = ['Rodel', 'Mike', 'Ronnie', 'Betus']; function firstAndLast(myArr) { var firstItem = myArr[0]; var lastItem = myArr[myArr.length - 1]; var objOutput = {}; objOutput[firstItem] = lastItem; return objOutput; } var display = firstAndLast(myArray); console.log(display);