I have an array to be like this var arr = [0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5, 5, 5, 5, 5, 5].
so it contains duplicate values. In here last index value of 
'0' is '3',
'1' is '4',
'2' is '5',
'3' is '13',
 and so on.
 And i counted total duplicate values 
var counts = {};
arr.forEach(function(x) { counts[x] = (counts[x] || 0)+1; })
but i want to know last duplicate value index only. please help me.
thanks in advance
var arr = [0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5, 5, 5, 5, 5, 5];
var existingItems = {};
arr.forEach(function(value, index) {
    existingItems[value] = index;
});
console.log(existingItems);
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With