This is possible with hidden tags. Any tag can be hidden by adding a:hide attribute so you can have something like the following:
var foo = [ <span a:foreach="foo" a:as="bar" a:hide>$bar</span> ];
a:hide makes the tag itself hidden from the rendered output, so it doesn't matter if the tag is a <span>, <foo> or <bar> it will be all the same. There is also the <a:span> tag, which is a dynamic tag that is hidden by default. With <a:span> it requires less typing:
var foo = [ <a:span foreach="foo" as="bar">$bar</a:span> ];
I hope this helps.
- Erdinc