I am kind of very new to javascript world. I have a doubt. How do i add/append new values to existing hash. example
var setname = 'set_1', elements = {};
elements[setname] = ['beer','water','wine'];
alert(elements['set_1']);
Now how do i dynamically add more elements to set_1 key? like to extend the set_1 with coffee tea.
Sorry if this question has been repeated and is very trivial, i did my search. I found one article realted to it,how to assign variable value as variable name in a hash?
Here,
elements['set_1']is just a normal Javascript array. The fact that it is a property of theelementsobject is completely immaterial to how it behaves. You can add items to it in the normal Javascript way: withpush:If you don’t know what the property’s name will be when you write your code, you can do exactly the same with a variable: