var blocks = ['#block1', '#block2'], $(blocks.toString()).each(function(index) { this.dataset.name = 'block' + index; });