Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

163
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda