Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

234
Views
I cant use a part of data directly I have to use another variable in between

I am really new to programming and my questions are very really not good Please forgive me if I am wasting your time Why when I use labels indirectly in DatatoBarChartJS (using a "label") it works

const DataFromDataBase  = {
  label :['January', 'February', 'March', 'April', 'May', 'June', 'July'],
  datasets : [  {datasetName:'Dataset 1', data:[1,3,5,2,5,2,6]},{datasetName:'Dataset 2', data:[4,6,5,2,5,2,6]} ],
}
const label =dataFromDataBase.label;
const color = tinycolor();


const DatatoBarChartJS  = {
  label,
  datasets : dataFromDataBase.datasets.map((dataset)=>{
        return{
          label:dataset.datasetName,
          data : dataset.data,
          backgroundColor:color.toRgbString ,
        }     
    }
  )
}

but when I use it inderectly it dosnt work?

const DataFromDataBase  = {
  label :['January', 'February', 'March', 'April', 'May', 'June', 'July'],
  datasets : [  {datasetName:'Dataset 1', data:[1,3,5,2,5,2,6]},{datasetName:'Dataset 2', data:[4,6,5,2,5,2,6]} ],
}
const label =dataFromDataBase.label;
const color = tinycolor();


const DatatoBarChartJS  = {
  DataFromDataBase.label,
  datasets : dataFromDataBase.datasets.map((dataset)=>{
        return{
          label:dataset.datasetName,
          data : dataset.data,
          backgroundColor:color.toRgbString ,
        }     
    }
  )
}

the problem is problem

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

When creating an object using the curly bracket syntax, you usually need to provide the name of the fields and their associated value.

const cat = {
  cute: true,
  legCount: 4,
  sound: 'miaw'
};

Depending on what "version of Javascript" you are using, there is a shorthand syntax that you can use:

const cute = true;
const legCount = 4;
const sound = 'miaw';
const cat = {
  legCount,
  sound,
  cute
}

When doing this, the name of the field will be the name of the variable, and the value of the field will be the value of the variable.

The reason you cannot use that syntax in your case is because what you are referencing is not a variable, it's a field within an object. And it kind of makes sense, because the result would be ambiguous:

// Would the result be this?
{ DatatoBarChartJS: { label: ['January', 'February', 'March', 'April', 'May', 'June', 'July'] } }
// Or this?
{ 'DatatoBarChartJS.label': ['January', 'February', 'March', 'April', 'May', 'June', 'July'] }
// Or this?
{ label: ['January', 'February', 'March', 'April', 'May', 'June', 'July'] }

You can find more information in Mozilla's object initialization documentation

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!