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

101
Vistas
how to convert a js object into a dot notation string

I have a javascript plain object like this one: {a: {b: 1} } and I want to convert it to a dot-notation string like this a.b = 1

use case:

sending the object to a plain-text environment such as cli or as a url parameter.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It's rather hard to tell whether this is what you want, but something like this would flatten a tree of objects into a list of dotted paths...

var data = {
  a: {
    b: 1,
    c: {
      d: 8
    }
  },
  e: {
    f: {
      g: 9
    },
    h: 10,
    i: [1, 2, 3]
  }
};


function toDotList(obj) {
  function walk(into, obj, prefix = []) {
    Object.entries(obj).forEach(([key, val]) => {
      if (typeof val === "object" && !Array.isArray(val)) walk(into, val, [...prefix, key]);
      else into[[...prefix, key].join(".")] = val;
    });
  }
  const out = {};
  walk(out, obj);
  return out;
}

console.log(toDotList(data));

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