5
I’m trying to generate a array made up of others arrays dynamically. For example:
check = function (title, filter) {
if (checked.indexOf(title) !== -1) {
checked[title].push(filter);
} else {
checked.push(title);
}
};
check('arraypai','conteudo');
check('arraypai','outroconteudo');
So that the result would be:
[
arraypai[conteudo,outroconteudo]
]
and then...
check('arraymae','coisa');
check('arraymae','outracoisa');
and the result would be:
[
arraypai[conteudo, outroconteudo],
arraymae[coisa, outracoisa]
]
I think what you want is a dictionary of arrays, right? Like:
{ arraypai:[conteudo, outroconteudo], arraymae:[coisa, outracoisa] }
. Alternatively, you can have an array of name/array pairs, type:[{nome:arraypai, array:[conteudo, outroconteudo]}, {nome:arraymae, array:[coisa, outracoisa]}]
. P.S. If this is the first case, simply replacechecked.push(title)
forchecked[title] = [filter]
.– mgibsonbr
It needs to be array inside array, because then, at another time, I need to give a . Join(',') in each main array.
– Marcelo Aymone
So you’re in trouble, because the most you’re gonna get is
[[conteudo, outroconteudo], [coisa, outracoisa]]
. There are no associative arrays in Javascript...– mgibsonbr
If I could create the arrays inside an object, array dictionary, as mentioned, would still work.
– Marcelo Aymone
The closest to a true associative array in JS is a literal object, as suggested by @mgibsonbr. Anything, reformulates the question :D
– Rui Pimentel