Skip to content
Advertisement

Get the first and last item in an Array – JS

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 item as the key and the last item as the value.

JavaScript

however this one gets me into trouble. It says undefined. Any idea why is that?

Advertisement

Answer

I’ve modified your code :

JavaScript

UPDATE: New Modification

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement