With javascript, is it possible to define a variable's name with another string value?
Posted
by Joren
on Stack Overflow
See other posts from Stack Overflow
or by Joren
Published on 2010-04-09T16:44:39Z
Indexed on
2010/04/09
16:53 UTC
Read the original article
Hit count: 217
JavaScript
Example, I have an array called 'categories' with the value ['4','9']. I'm trying to use that value with the name of a previously defined array. I have several arrays defined earlier called row1, row2, row3 etc. I'm also using jQuery.
Trying to do something like this:
for (i=0; i<categories.length; i++) {
row+categories[i].push($(this).attr('id'));
console.log(row+categories[i]);
}
Obviously row+categories[i] doesn't work, but maybe gives you an idea of what I'm trying to do? In this case to push that id value onto the array 'row4' the first time it loops through and then 'row9' the second time.
Thanks for your help!!
© Stack Overflow or respective owner