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

102
Views
Parse a string with a key and value to an object

[Edited because my question was not clear]

I would like to parse each string from an array into an object as its key with an assigned value e.x.:

There is an array called dates.

This is dates[0]

"2022-02-01"

And I would like to parse it in an object that looks like this:

let datesObj = { "2022-02-01": {selected: true, marked: true} }

I have looked into JSON.parse() but I have not been able to apply it to my needs in this case (if that is even the solution).

I haven't been able to find a suitable solution, so a big thank you to anyone willing to help.

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

0

wrap your string with breakets

var mystring='{"2022-02-01": {selected: true, marked: true}}'; 

and then try parsing it with

var myobj=JSON.parse(mystring);
about 4 years ago · Juan Pablo Isaza Report

0

Like this?

function parse(date)
{
    const res = {}
    res[date] = {
        selected: true, 
        marked: true
    }
    return res;
}
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!