5

How can i add two objects (myobject1 and myobject2) in an Array of objects (myArray)?

myArray.push(myobject1) doesn't work.

var myArray=  [{value:[1,2,3],label:red},{value:[1,2,3],label:blue},{value:[1,2,3],label:yellow}];

var myobject1={type: 'spline',name: 'Moyenne',data: moyenneArray,marker: {lineWidth: 2,lineColor: getOptions().colors[3],fillColor: 'white'}};

var myobject2= {type: 'pie',name: 'Total entreprise',data: seriesTotal,center: [100, 30],size: 100,showInLegend: false,dataLabels: {enabled: false}};};
3
  • Post your full code, so we can help accurately. Commented Jun 16, 2018 at 19:45
  • I don't think you can have a function in an array. The getOptions().colors will cause the push to not work. Commented Jun 17, 2018 at 1:24
  • @AllanF.Gagnon — You can have a function in an array, but that syntax will put the value of the colors property of the return value of calling the getOptions function in the array … which probably isn't a function. Commented Jun 17, 2018 at 6:35

2 Answers 2

2

Did you try this

myArray.push(myobject1);
Sign up to request clarification or add additional context in comments.

Comments

0

If you want to push them both you could always concat myArray.concat([myObject1,myObject2])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.