Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

225
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda