0
How can I always catch the last object of 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',
}
]
0
How can I always catch the last object of 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',
}
]
3
You can search by length using .length
minus 1 that will always return the last item
let arr = [ '0', '1', '2', '3', '4', '5']
console.log(arr[arr.length -1])
Browser other questions tagged javascript
You are not signed in. Login or sign up in order to post.
myArray[myArray.length - 1];
– Vinícius
array[array.length - 1]
/ 2.a.slice(-1)[0]
/ 3.array.pop()
– Guilherme Nascimento