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

219
Views
Changing of values of keys in JSON

I have an application, where I use MongoDB, Express and MongoDB. On server side I received data by using find in such look - array of objects(JSON), which is named upProbations. For example, I find information about Max:

[        
  {
        Name: 'Max',
        DateOne: 2019-01-01T00:00:00.000Z,
        DateTwo: 2019-04-01T00:00:00.000Z,
        Info: 'Cheerful'
  }
]

I want to change information a bit - fields DateOne and DateTwo. They have both types Date and I want to leave only 2019-01-01 and same for DateTwo, so i don't need time(hour, minute, second). The result should look like this:

[        
  {
        Name: 'Peter',
        DateOne: 2019-01-01,
        DateTwo: 2019-04-01,
        Info: 'Cheerful'
  }
]

This result I will futher use for antoher calculations. I have tried such code, but it's not working:

upProbations = upProbations.map(function(a) {
    a.DateOne = a.DateOne.toISOString().replace('T', ' ').substr(0, 10);
return a;
})
console.log(upProbations);

In which way I can do this?

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

0

let upProbations = [
  {
    Name: "Max",
    DateOne: 2019-01-01T00:00:00.000Z,
    DateTwo: 2019-04-01T00:00:00.000Z,
    Info: "Cheerful",
  },
];

upProbations = upProbations.map((eachObject) => {
  const { DateOne, DateTwo, Name, Info } = eachObject;
  return {
    Name,
    DateOne: DateOne.toString().split("T")[0],
    DateTwo: DateTwo.toString().split("T")[0],
    Info,
  };
});

console.log(upProbations);

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!