Enumerate an array, grouping duplicates
Dyalog APL, 5 bytes
(⊂,)⌸
Try it online!
,⌸
for 2 bytes almost works, but has trailing zeroes :/
J, 12 bytes
~.,&.><@I.@=
Zero-indexed.
Try it online!
If you can remove all of the work I'm doing with boxes, you can probably reduce the bytecount by quite a bit. I'm going to see if I can figure that out.
Explanation
This is probably too early to be explaining (there ought to be more golfs).
~. ,&.> <@I.@=
= Self-classify (comparison of each unique element to array)
@ Composed with
I. Indices of ones (where it's equal)
@ Composed with
< Boxed (how we deal with arrays of unequal length)
,&.> Joined with
> Unbox each
, Concatenate
&. Box again
~. Unique elements
05AB1E, 10 bytes
ÙεDIQƶ0K)˜
Try it online!
Explanation
Ù # remove duplicates
ε # apply to each element
D # duplicate
IQ # compare for equality with input
ƶ # multiply each element by its index (1-based)
0K # remove zeroes
)˜ # wrap in a flattened list