I am trying to update multiple elements at once in a multidimensional array/object and having errors with .push and other options I have tried.
var FEtypes= {
textTemplate: {
type :"Text",
size : 50,
required : "no",
FEadd : '<input>',
label : 'Label',
top : 0,
left : 0
},
textareaTemplate: {
type : "Textarea",
cols : 30,
rows : 5,
FEadd :'<textarea>'
}
}
This works, but trying to do in one line.
FEtypes[1].left = someVariable1;
FEtypes[1].top = someVariable2;
I have been unsuccessful with:
FEtypes[1].push( {left:someVariable1, top:someVariable2} );
I keep getting an error that this is not a function or it does nothing.
FEtypesis an object, not an array.Pushis only available on arrays.If you want to store this structure in an array, it would look something like:
Then
If you want to modify multiple properties at once, the jQuery extend function will get you what you want:
But I think your original structure is more suitable. Just ditch arrays, and do this:
Or, again, with just one line with jQuery: