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

117
Vistas
How to create an array of objects with strings and arrays

I have to create an array in the following format

var myData = [
  {
    x: "10:00",
    y: [15, 30],
  },
];

Where my code looks like

myData.push({
  x: startingHoursToPush + ":00",
  y: "[" + startingHours[1] + "," + endingHours[1] + "]",
});

but the result I get is as following

x: "11:00"
y: "[15,30]"

I need to make the values for y an array instead of a string

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

use either [ ]

myData.push({
  x: startingHoursToPush + ":00",
  y: [startingHours[1],endingHours[1]],
});

DEMO FIDDLE 1

OR

use array inside

myData.push({
      x: startingHoursToPush + ":00",
      y: new Array(startingHours[1],endingHours[1]),
    });

DEMO FIDDLE 2

about 4 years ago · Juan Pablo Isaza Denunciar

0

You are making a string instead of an array, try this instead

myData.push({
  x: startingHoursToPush + ":00",
  y: [startingHours[1], endingHours[1]],
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

JS is wonderful. Just wrap it in [] brackets.

myData.push({
  x: startingHoursToPush + ":00",
  y: [startingHours[1] , endingHours[1] ],
});

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