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

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

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