liam
liam

Reputation: 361

Json syntax error:Uncaught SyntaxError: Unexpected token [

window.addEventListener('load, initialize());

'use strict'

console.log('Im working);

var c = [
    ["TEST!","TEST@"]
];

function initialize() {
    console.log(c[0].[1]);
}

I have tried for hours to make this code print out "TEST!", But the google console debugger, will no matter what I try, will say that the last set of square brackets is a unexpected Token. At this point, I just don't know what to do.

Upvotes: 0

Views: 269

Answers (1)

epascarello
epascarello

Reputation: 207557

bracket notation does not use dots

var c = [ [1,2] ];
console.log(c[0][1]);

Another issue with your code is

window.addEventListener('load, initialize());

If initialize is returning a function it is correct. If it is not returning a function, than you are calling the method before the page load and assigning what it returns to the load event listener.

Upvotes: 2

Related Questions