-1

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?

2
  • what should your code doing?? or what you expect output to be?? Commented Nov 1, 2015 at 14:21
  • exclude_array[id] should be an array. So exclude_array[id][0],exclude_array[id][1] etc Commented Nov 1, 2015 at 14:23

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

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.