___ ___ erkimt Take last array object [duplicate] ______ qstntxt ___

How can I always get the last object from the array at the moment I'm using the following function but only takes the first one.

%pre%     
______ azszpr326152 ___

You can search for length using %code% less than 1 that will always return the last item

%pre%
    
___

0

How can I always get the last object from the array at the moment I'm using the following function but only takes the first one.

var IDs = arrayIds[0].id;

[
  {
    id: '1',
  },
  {
    id: '2',
  },
  {
    id: '3',
  }
]
    
asked by anonymous 30.08.2018 / 17:05

1 answer

3

You can search for length using .length less than 1 that will always return the last item

let arr = [ '0', '1', '2', '3', '4', '5']


console.log(arr[arr.length -1])
    
30.08.2018 / 17:12