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

158
Vistas
Create JavaScript Object from string

Could you please help me to prepare below Object from string using JS. I am new in JS.

health status index       uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   new_log jdbc1233q6AiRUSRCczayjz0rw   1   1     603442            0    127.6mb        127.6mb

From above string how do I create below object?

{
    "health": "yellow",
    "status": "open",
    "index": "new_log",
    "uuid": "jdbc1233q6AiRUSRCczayjz0rw",
    "pri": "1",
    "rep": "1",
    "docs.count": "603442",
    "docs.deleted": "0",
    "store.size": "127.6mb",
    "pri.store.size": "127.6mb"
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Here is how you can use split

const str = `health status index       uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   new_log jdbc1233q6AiRUSRCczayjz0rw   1   1     603442            0    127.6mb        127.6mb`
const lines = str.split(/\n/); // split lines on \n
const arrs = lines.map(line => line.split(/\s+/)); // split line on whitespace
const obj = {}; // define an object, we could use reduce but this is easier to read
arrs[0].forEach((word,i) => obj[word] = arrs[1][i])
console.log(obj); // show it
console.log(JSON.stringify(obj)); // show the JSON

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