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

245
Views
How to push data which is not hard coded into variable?

I am trying to push data into a variable Data[] but all I have is an example of how to do this hard coded:

var data = [{
    id: "1",
    name: "Development Life Cycle",
    actualStart: Date.UTC(2018, 01, 02),
    actualEnd: Date.UTC(2018, 06, 15),
    children: [{
            id: "1_1",
            name: "Planning",
            actualStart: Date.UTC(2018, 01, 02),
            actualEnd: Date.UTC(2018, 01, 22),
            connectTo: "1_2",
            connectorType: "finish-start",
            progressValue: "75%"
        },
        // more data goes here
    ]
}];

I tried with following code but it doesn't seem to work:

ganttdata = [];
// DUMMY DATA
id = 10;
RFInum = 'asfd';
start= 1;
LTIOV = 2;
progressValue = 10;

ganttdata.push("{id:"+id, "parent: null", "name:"+RFInum, "actualStart: Date.UTC("+start+")", "actualEnd: Date.UTC("+LTIOV+")", "progressValue:"+progressValue+"%}");
console.log(ganttdata);

Anyone know how to write this?

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

0

You are currently inserting your data as a string and not as an object.

I recreated your approach and inserted your data as an object into the ganttdata array.

Date documentation

var ganttdata = [];
// DUMMY DATA
var id = 10;
var RFInum = 'asfd';
var start = Date.UTC(2021, 12, 31);
var LTIOV = Date.UTC(2021, 12, 31);
var progressValue = 10;

ganttdata.push({
  id,
  parent: null,
  name: RFInum,
  actualStart: start,
  actualEnd: LTIOV,
  progressValue: `${progressValue}%`,
});

console.log(ganttdata);

Or if you want to append some data to an existing object at a specific index:

var data = [{
  id: 1,
  name: 'test'
}];

console.log('before:', data);

data[0].extend = 'hello World';
data[0].foo = 'bar';

console.log('after:', data);

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!