Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

233
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda