I want to do:
mkArray(xml, "artist", "namespace.newarray");
function mkArray(xml, tag, store){
store = [];
$(xml).find(tag).each(function(i,v){
store.push($(this).text());
});
console.log(store);
}
But of course this overwrites what store is, rather than using it as a reference to a property of namespace. What’s the correct way of going about it? I thought window[store] would work, but didn’t have any luck.
In general, it’s better to avoid functions that have side effects, e.g. change their arguments. If your function is supposed to create something, just return this “something”:
If, for some reason, that doesn’t work for you, you can also modify the function argument, but the object itself should be created in the calling code: