JSFiddle - React, Tailwind, and code Playground

by Rafael Nepomuceno

HTML

<a class="button" id="arr1">Button1</a> |
<a class="button" id="arr2">Button2</a> |
<a class="button" id="arr3">Button3</a>

CSS

a{
    cursor: pointer;
}

JavaScript

$('.button').click(function () {

    var myvar = this.id;
    myvar = new Array(); // I need use ID as array name

    // Code for button1
    arr1['value1'] = 'text 1';
    arr1['value2'] = 'text 2';

    // Code for button2
    arr2['value3'] = 'text 3';
    arr2['value4'] = 'text 4';
    
    // Code for button3
    arr2['value5'] = 'text 5';
    arr2['value6'] = 'text 6';

    // Click on Button1, the alert below need show "text 1"
    alert(myvar['value1']); // "text 1"
    
    // alert(myvar['value1']);
});