I'm struggling with a frontend processing of a response from a server that spews out the event reviews in the season. There can be multiple reviewers for the same event and the simplified version of response looks like this:
[{"id":"3","reviewer_id":"4","event_id":"3","review":"a"},
{"id":"19","reviewer_id":"3","event_id":"4","review":"b"},
{"id":"20","reviewer_id":"1","event_id":"4","review":"b"}]
I want to make and array with events where array index would be defined by event_id, therefore I do something like this:
var events = new Array();//define the recipient array
$.each(response, function(index, row) {
if (!(jQuery.isArray(events[Number(row.event_id)]))) {//if a variable by this index is not array then...
var events [Number(row.event_id)] = new Array();// ...declare it as array, I get error thrown here: "Uncaught SyntaxError: Unexpected token ["
}
events[Number(row.event_id)].push(row);//push current row into appropriate recipient array member
});
As noted in the code, I have an error thrown
Uncaught SyntaxError: Unexpected token [ in line 4.
Any help would be appreciated.