0

I'm getting an error (it's javascript btw), and even after a lot of googling, I cannot find where it comes from. It says "SyntaxError: missing ; before statement", with an arrow pointing to the point in between nmwoo_vars and file_meta. Anyone who knows how to solve it?

var nmwoo_vars.file_meta = [{"label":"Graveren","type":"checkbox","options":"Ja, graveer mijn bril","price":"10"},{"label":"Gravering","type":"text","options":"","price":""}];
1
  • 1
    Does nmwoo_vars exist? Is the statement above this assignment terminated with a ;? Commented Aug 3, 2014 at 14:56

2 Answers 2

2

A var keyword is used to declare variables. You're just adding a property to an object, so var is incorrect.

nmwoo_vars.file_meta = [{"label":"Graveren","type":"checkbox","options":"Ja, graveer mijn bril","price":"10"},{"label":"Gravering","type":"text","options":"","price":""}];

is all you need (assuming "nmwoo_vars" is itself a variable that references an object).

Parsers aren't very smart, in most cases. The error you got means that the parser made an assumption about what your code is trying to do. In real life those assumptions are wrong probably more often than they're right, so such messages don't help much, and are especially baffling to those learning the language. Usually it's a good idea to just examine your code and verify to yourself that it's syntactically correct, ignoring the specifics of the error.

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

Comments

0

Here is a sample code to test your object creation, it works fine.

var nmwoo_vars = new Object();
nmwoo_vars.file_meta = [{"label":"Graveren","type":"checkbox","options":"Ja, graveer mijn    bril","price":"10"},{"label":"Gravering","type":"text","options":"","price":""}];

alert(nmwoo_vars.file_meta[0].label);

As Pointy mentioned you cannot initialize the object on the fly. You must create the object first and then assign its properties.

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.