Lets say there is an array of objects
array = [{ id : 1, name : 'aaa' }, { id : 1, name: 'asd' }, id : 2, name : 'asd' ]
in a loop eg
array.forEach(a =>{ currentId = a.id }
how to check if current id is same or not as prev id
Lets say there is an array of objects
array = [{ id : 1, name : 'aaa' }, { id : 1, name: 'asd' }, id : 2, name : 'asd' ]
in a loop eg
array.forEach(a =>{ currentId = a.id }
how to check if current id is same or not as prev id
2
Answers
You can use the index to get the previous entry:
You can use
reduce
like: