var x = [];
$('input').click(function(){
$(this.value).push('Hello'); //x.push('Hello');
alert(x) //Expected Result: 'Hello'
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type='button' value='x'>
I want to push the value Hello
to the local variable array with the identifier equal to that of the value of the button that was clicked. For example, if the button with the value="x"
is clicked, I want var x = ...
to be updated. Similarly, if value="y"
is clicked, var y = ...
should be updated.
Is that possible?