Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1066654 of SyntaxError: missing ] after element list

  • Revision slug: Web/JavaScript/Reference/Errors/Missing_bracket_after_list
  • Revision title: SyntaxError: missing ] after element list
  • Revision id: 1066654
  • Created:
  • Creator: fscholz
  • Is current revision? Yes
  • Comment new page

Revision Content

{{jsSidebar("Errors")}}

Message

SyntaxError: missing ] after element list

Error type

{{jsxref("SyntaxError")}}.

What went wrong?

There is an error with the array initializer syntax somewhere. Likely there is a closing bracket ("]") or a comma (",") missing.

Examples

Incomplete array initializer

var list = [1, 2,

var instruments = [
  "Ukulele",
  "Guitar",
  "Piano"
};

var data = [{foo: "bar"} {bar: "foo"}];

Correct would be:

var list = [1, 2];

var instruments = [
 "Ukulele",
 "Guitar",
 "Piano"
]; 

var data = [{foo: "bar"}, {bar: "foo"}];

See also

  • {{jsxref("Array")}}

Revision Source

<div>{{jsSidebar("Errors")}}</div>

<h2 id="Message">Message</h2>

<pre class="syntaxbox">
SyntaxError: missing ] after element list
</pre>

<h2 id="Error_type">Error type</h2>

<p>{{jsxref("SyntaxError")}}.</p>

<h2 id="What_went_wrong">What went wrong?</h2>

<p>There is an error with the array initializer syntax somewhere. Likely there is a closing bracket ("<code>]</code>") or a comma ("<code>,</code>") missing.</p>

<h2 id="Examples">Examples</h2>

<h3 id="Unescaped_strings">Incomplete array initializer</h3>

<pre class="brush: js example-bad">
var list = [1, 2,

var instruments = [
  "Ukulele",
  "Guitar",
  "Piano"
};

var data = [{foo: "bar"} {bar: "foo"}];
</pre>

<p>Correct would be:</p>

<pre class="brush: js example-good">
var list = [1, 2];

var instruments = [
 "Ukulele",
 "Guitar",
 "Piano"
]; 

var data = [{foo: "bar"}, {bar: "foo"}];</pre>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{jsxref("Array")}}</li>
</ul>
Revert to this revision