I am working with a Javascript library that consumes JSON notation - as a function parameter.
In an attempt to make my code more modular I have modified the calls to accept Javascript Objects.
So whereas the input was this
{ title: {
text: 'Some Text'
},
credits: {
enabled: false
},
tooltip: {
pointFormat: '{point.name}: <b>{point.y} yrs.</b>'
} }
I am creating an object (in an Array, because I want to carry several of them) like this:
genericObject = new Array(
{ title: {
text: 'Some Text'
},
credits: {
enabled: false
},
tooltip: {
pointFormat: '{point.name}: <b>{point.y} yrs.</b>'
} }
);
And then pass the function (that previously took the JSON notation) simply: genericObject[0], a first-class JS object!
That all works well. Additionally, I can make changes to the values genericObject[0]['text'] = 'NEW TEXT';
without difficulty.
The problem I face is with another aspect of all this and it is two-fold.
What I showed above was just a snippet. The entire JSON input includes a reference to an array like this:
{ title: {
text: 'Chart Text'
},
credits: {
enabled: false
},
tooltip: {
pointFormat: '{point.name}: <b>{point.y} yrs.</b>'
},
series: [{
type: 'pie',
name: 'Series Name',
data: seriesData //this is an array
}]
}
And âseriesDataâ is defined like this:
seriesArray = new Array(
{name: 'Before Event',
y: 115,
color: '#8E8E93'},
{name: 'Since Event',
y: 35,
color: '#5AC8FA'}
);
Here comes the real question
How can I surgically modify both (or either) of those values of ânameâ and the values of âyâ within that object in the array? The two comma-separated groups are not indexed - are they?
I have tried things like seriesArray[0][0]['name'] = "BLAH"
and seriesArray[0]['name'] = "NEW NAME"
and even seriesArray[0][].name = "HELP ME"
but with no success.
Fundamentally, this is a simple problem. For some reason I just cannot get my head wrapped around the relationship of the fields (attributes?) within the Javascript Objects here.