user892134
user892134

Reputation: 3224

Jquery multidimensional array not working

I'm trying to do a multidimensional array in jquery.

var exclude_array = {}; 
$(this).siblings("tr[data-id='" + id + "']").each(function() {
    var id = $(this).attr("data-id");
    var item_id = $(this).children("td:eq(3)").find("input[name='exclude']").attr("data-item_id");
    exclude_array[id][] = item_id;
});

I get the error Uncaught SyntaxError: Unexpected token ], with exclude_array[id][] How do i solve?

Upvotes: -1

Views: 71

Answers (1)

Antti29
Antti29

Reputation: 3033

It seems you're trying to push the item_id into exclude_array. The array[] syntax is not used in JavaScript. Instead, you must use .push().

Before that, make sure that the key is defined and that it is an array.

if (exclude_array[id] === undefined)
    exclude_array[id] = [];
exclude_array[id].push(item_id);

Upvotes: 1

Related Questions