How to go deep into the object and take the innermost object?

  • 0
    const someObj = {
      title: 1,
        children: {
          name: 'test',
          title: 2,
          children: {
            title: 3,
          }
       }
    }


    you need not only to return the {title: 3} object, but also, if the external has a name field, then return this field too, that is, it should get {title: 3, name: 'test'}
    JavaScript Nolan Rios, Nov 30, 2020

  • 2 Answers
  • 0
    const getLast = (obj, parentName) =>
    obj.next instanceof Object
    ? getLast(obj.next, obj.name)
    : { ...obj, parentName };
    Anonymous

  • 0
    You asked already))

    How to go deep into the object?
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!