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

115
Views
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 answers
Answer question

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 Report

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 Report

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 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!