0

I'm writing a javascript slideshow, but Firebug is telling me there's an error in the syntax, or something, but I just can't see what's wrong! Here's the code snippet:

<script language="javascript" type="text/javascript">

var data = new Array();

var data[0] = new Array();
var data[0]['id'] = 'example';
var data[0]['height'] = 190;

</script>

Firebug says:

missing ; before statement  

var data[0] = new Array();

The problem? Well, I just don't understand where the problem is! Could anyone explain the mistake to me? Thank you!

2 Answers 2

5

You can't declare an array index. Lose the var on all but the first line.

Sign up to request clarification or add additional context in comments.

3 Comments

Right answer, and additionally you should not declare an array via new Array();, but via [], because that is considered best practise. so the first line should say var data = [];
It also looks like he wants {} instead of new Array for the second line
Thank you for the quick answers! That fixed the problem. Also thank you for the 'best practice' tips!
1

Keep only the first "var" statement, it will work like this:

var data = [];

data[0] = [];
data[0]['id'] = 'example';
data[0]['height'] = 190;

Take a look http://jsfiddle.net/cmTBc/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.