javascript - Pushing an array into another array? -
i have array:
var filemetadata = [];
in loop want push things array:
$('#gallery-manager-add-form .galleryimage').each(function(){ filemetadata.push(mytestarray); });
for testing mytestarray is:
var mytestarray = new array(2); mytestarray['a'] = 'foo'; mytestarray['b'] = 'bar';
the problem is, when contents of array, it's comma (,).
any ideas going wrong?
that's because you're confusing arrays , objects (which should use).
if keys 'a'
, 'b'
, use
var mytestarray = {}; mytestarray['a'] = 'foo'; mytestarray['b'] = 'bar';
if want use array, use
var mytestarray = []; mytestarray.push('foo'); // no explicit key mytestarray.push('bar');
you saw comma because, standard representation of array doesn't properties, printing equivalent of [[],[]].tostring()
","
.
Comments
Post a Comment