Find element by ID and Push to json

I have a json object:

const data = {
  id: 'root',
  name: 'Parent',
  children: [
    {
      id: '1',
      name: 'Child - 1',
    },
    {
      id: '3',
      name: 'Child - 3',
      children: [
        {
          id: '4',
          name: 'Child - 4',
        },
      ],
    },
  ],
};

And I want to add new children arrays dynamically to any parent element, by id. E.g. I want to find element with id=’4′ and add children: [{ id:’5′, name: ‘Child – 4’ }]

35 thoughts on “Find element by ID and Push to json”

  1. Pingback: cialis sex pill
  2. Pingback: canadian viagra
  3. Pingback: buy viagra
  4. Pingback: cialis mg
  5. Pingback: order viagra
  6. Pingback: www.cialisgap.com

Leave a Comment