Use array in jquery to count through numbers 1-4

I would like to shorten the following code snippet. Basically, I would like to count through from 1 to 4 and if I remember correctly I could do this with an array? $(‘.anchor-4’).on(‘click’, function(event){ $(‘#ui-id-4’).click(); }); $(‘.anchor-3’).on(‘click’, function(event){ $(‘#ui-id-3’).click(); }); $(‘.anchor-2’).on(‘click’, function(event){ $(‘#ui-id-2’).click(); }); $(‘.anchor-1’).on(‘click’, function(event){ $(‘#ui-id-1’).click(); }); Thanks a lot for your help!

Details