Get the first and last item in an Array - JS

后端 未结 6 1595
面向向阳花
面向向阳花 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:49

    well, I have another idea... for ex.:

    const all = ['food', 'clean', 'cat', 'shower', 'work out']
    console.log(`you have ${all.length} all!`)
    console.log(`Todo: ${all[0]}`)
    console.log(`Todo: ${all[all.length - 1]}`)
    

提交回复
热议问题