1

How would I target "data" in this array?

var waterBarData = {
labels: ["January", "February", "March", "April", "May", "June"],
datasets: [
    {
        label: "My Second dataset",
        fillColor: "rgba(98,203,49,1.0)",
        strokeColor: "rgba(98,203,49,0.8)",
        highlightFill: "rgba(98,203,49,0.75)",
        highlightStroke: "rgba(98,203,49,1)",
        data: [28, 48, 40, 19, 86, 27]
    }
]};

My guess is below but that doesn't seem to be working

waterBarData.datasets[data]

1 Answer 1

4

datasets in your object is an array so that you need to access it by index:

waterBarData.datasets[0]['data'];

// or using dot notation
waterBarData.datasets[0].data;
Sign up to request clarification or add additional context in comments.

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.