79384826

Date: 2025-01-24 15:33:28
Score: 1.5
Natty:
Report link

You can also use a handy lib called dot-object. Particularly dot.dot() method

var dot = require('dot-object');

var obj = {
  id: 'my-id',
  nes: { ted: { value: true } },
  other: { nested: { stuff: 5 } },
  some: { array: ['A', 'B'] }
};

var tgt = dot.dot(obj);

This will result in

{
  "id": "my-id",
  "nes.ted.value": true,
  "other.nested.stuff": 5,
  "some.array[0]": "A",
  "some.array[1]": "B"
}

Link: https://github.com/rhalff/dot-object?tab=readme-ov-file#convert-object-to-dotted-keyvalue-pair

Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: El NiƱo