I have an array that looks like this:
let arr = ['11','44','66','88','77','00','66','11','66']
Within this array, there are duplicate elements:
- '11' at position 7
- '66' at positions 6 and 8
I need to loop through the array to identify duplicated elements and replace them from the second occurrence with a string indicating the index of the first occurrence.
The resulting array would be:
let newarr = ['11','44','66','88','77','00','appears at 2','appears at 0','appears at 2']
As shown, the duplicates are replaced with strings like:
"appears at n" where "n" represents the index of the first occurrence