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
I've modified your code :
var myArray = ['Rodel', 'Mike', 'Ronnie', 'Betus'];
function firstAndLast(array) {
var firstItem = myArray[0];
var lastItem = myArray[myArray.length-1];
var objOutput = {
first : firstItem,
last : lastItem
};
return objOutput;
}
var display = firstAndLast(myArray);
console.log(display);
UPDATE: New Modification
var myArray = ['Rodel', 'Mike', 'Ronnie', 'Betus'];
function firstAndLast(array) {
var firstItem = myArray[0];
var lastItem = myArray[myArray.length-1];
var objOutput = {};
objOutput[firstItem]=lastItem
return objOutput;
}
var display = firstAndLast(myArray);
console.log(display);