Shahmee Shahmee - 1 year ago 111
Javascript Question

set jquery multidimensional array

I'm getting attribute values. I need to set into multidimensional array but it's showing error. where im getting wrong ?

var myArray = [];
$(id).closest('td').nextAll().find('input').each(function (n) {

myArray[x]['id'] = $(this).attr('data-id');
myArray[x]['year'] = $(this).attr('data-year');
myArray[x]['month'] = $(this).attr('data-month');
myArray[x]['amount'] = amount;


Answer Source

you are missing this line

myArray[x] = {};

before this line

myArray[x]['id'] = $(this).attr('data-id');

since you need to initialize this object first before setting properties to it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download