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

168
Views
Transform a string of an object to an object

I am trying to take an object from the server-side and bring it to an ejs file to use it in javascript.

The object inside the javascript looks like this:

   var span = document.createElement("SPAN");
   span.innerHTML = "<%= JSON.stringify(positions) %>";
   var positions = span.innerText;
   span.remove()
   console.log(positions)

and it returns a string like this one:

"
    {
        '0': { foo: foo },
        '1': { foo: boo },
        '2': { foo: doo }
    }
    "

Is there a way for me to do that?

Thanks!

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

0

You can just assign a variable to the stringified positions (no quotes) and it becomes a javascript object. Then to display it stringify that object again.

(This "renders it as JS from the outset").

const myJSObj = <%= JSON.stringify(positions) %>;
console.log(JSON.stringify(myJSObj));
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!