Reputation: 841
I have a multi dimensional array like this:
var firstElement = $(this).first();
fielddata = {
number: index,
attributes: [
{ 'label_text': firstElement.text(),
'label_width': firstElement.width(),
'label_height': firstElement.height(),
'label_color': firstElement.css('color')
}
]
}
How can I change one of the values inside the attributes part but by id? so I make 'label_text' a different value?
I do not want to use the index.
Upvotes: 0
Views: 137
Reputation: 36438
You don't have a multidimensional array. You have an object; one of its properties is an array of objects.
In this case, it looks like you want to update label_text
in the first (and only) object in the attributes
list. If that's correct:
fielddata.attributes[0].label_text = 'whatever';
Will work, as would:
fielddata.attributes[0]['label_text'] = 'whatever';
Upvotes: 4