Looks like you're actually off-track in a couple of different ways...
ElementCriteriaModel
This code is going to return an ElementCriteriaModel:
craft.tags.group('gameTags')
Think of an ElementCriteriaModel as being a pending search query... The only reason you'd need one is to either adjust the query further or run the query to get results.
Fortunately Craft is smart enough to automatically run an ElementCriteriaModel if you use it an another context. In fact, it will be automatically parsed as an array of the query results. When you let the query run automatically, it's as if you had appended .find
to the original line of code. If you append something like .first
to your code, it'll return only a single element.
See "Fetching the Elements" for more details.
JavaScript
As André pointed out in his answer, you'd want to wrap a string in quotes when passing it to JavaScript.
However, it looks like you're returning an array. So you'd probably need to manipulate that array however you'd like in Twig, before passing it to JavaScript as either a string or an array.
// Setting a string
var gameTags = "{{ myString }}";
// Setting an array
var gameTags = ["{{ myArray | join('","') }}"];
This operates under the assumption that myArray
is already an array of strings. But be careful... When you run your ElementCriteriaModel, you'll end up with an array of TagModels. You may need to extract the title
of each TagModel before throwing them to JavaScript.
Take note also of the Twig join
filter. That will combine your array of strings into a "superstring", which you can pass to JavaScript to build your JS array.
Hope that helps!