how to store an array via jquery data method and add to that array?
Since references to arrays are stored, you can do it like this:
var array = [1, 2, 3];
$.data(elem, "myArray", array);
// and later
$.data(elem, "myArray").push(4, 5, 6);
// and later
console.log($.data(elem, "myArray"));
//-> [ 1, 2, 3, 4, 5, 6 ]
Should be simple task:
$('#someelement').data('myarray', []);
// somewhere else
$('#someelement').data('myarray').push('foo');
// access
console.log( $('#someelement').data('myarray')[0] );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With