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

160
Views
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 answers
Answer question

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 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!