JSFiddle - React, Tailwind, and code Playground

by Nicolas PUJOL

HTML

<label data-plural="foos" data-id="1">Foo</label>
<label data-plural="bars" data-id="2">Bar</label>

JavaScript

var commands = [];
$('label').each(function(k,v) {
    var category = $(v).data('plural');
    var id = $(v).data('id');
   var temp = {};
   temp['show ' + category] = function() { window.alert(id + " " + category); exploreId(id, category); };
   commands.push(temp);
});
console.log(commands);
console.log(commands[0]['show foos']());