¿Podría ayudarme a preparar el siguiente objeto de cadena usando JS? Soy nuevo en 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.6mbDesde la cadena anterior, ¿cómo creo el objeto debajo?
{ "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" }Así es como puedes usar 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