tags:

views:

201

answers:

4
<script>
var tids = {
308: 1,
312: 1,
313: 1,
314: 1
};
</script>

results in "missing } in XML expression with an arrow pointing to the first colon in the JS error console. Isn't this a valid declaration?

A: 

i guess that the key cannot start with a number. try;

<script>
var tids = {
n308: 1,
n312: 1,
n313: 1,
n314: 1
};
</script>
returnvoid
A key can start with a number.
Doug Neiner
I'm pretty sure the key can be a number, I think I've used it before.
Topher Fangio
I guess not. The key cannot start with a number at least it be declared like a string (in that case is not a number anymore)
returnvoid
+3  A: 

First you should fix your <script> tag to

<script type="text/javascript">

Next, if you want to use numeric indexes, try to declare them as a string:

var tids = {
'308': 1,
'312': 1,
'313': 1,
'314': 1
};

Please note, however, that you will not be able to reference them in object notation (i.e. tids.308). You could simply use arrays instead of objects:

cballou
You could access it as tids['308'], though.
Rudi
it was the type that was causing it.
@cballout Good eye man!
Doug Neiner
A: 

This isn't an associative array -- it's just a JS object. I believe you need to make the keys strings instead of numeric.

var tids = {
"308": 1,
"312": 1,
"313": 1,
"314": 1
};

More info on associative arrays vs. regular objects.

bmoeskau
A: 

I have tried in both IE and FF and the code is fine. It should be the error of other codes.

Please use Firefox Web Developer and Firebug to find the source of error.

Billy