How could i fix in Recursion code in javascript

my code is like that. it was work at first.. not more

function HA7(arr, id) { 
  for (let i = 0; i < arr.length; i++) { 
    if(arr[i]['id']=== id) {
      return arr[i]
    }
      else if(arr[i]=== undefined && arr[i][id] === id  ) {
      return arr[i][id]
    }
      else if(arr[i][id] === undefined){
      return null ;
    }
    return HA7(arr[i],id)
  }
}

I wanna more continue work by recursive function .. but once agian only return null.
(i wanna catch case id value null or arr is undefined)

// example code.

let arr = [
  {
    id: 1,
    name: 'johnny',
  },
  {
    id: 2,
    name: 'ingi',
    children: [
      {
        id: 3,
        name: 'johnson',
      },
      {
        id: 5,
        name: 'steve',
        children: [
          {
            id: 6,
            name: 'lisa',
          },
        ],
      },
      {
        id: 11,
      },
    ],
  },
  {
    id: '13',
  },
];

let output = HA7(arr, 1);
console.log(output); // --> { id: 1, name: 'johnny' }

output = HA7(arr, 5);
console.log(output); // --> { id: 5, name: 'steve', children: [{ id: 6, name: 'lisa' }] }

output = HA7(arr, 99);
console.log(output); // --> null

How should I fix it more? please tell me a some tips ..

30 thoughts on “How could i fix in Recursion code in javascript”

  1. hey there and thank you for your information – I have
    certainly picked up anything new from right here. I did however expertise a few technical points using this website, as I experienced to reload the website a lot
    of times previous to I could get it to load correctly. I had
    been wondering if your web hosting is OK? Not that I’m complaining,
    but slow loading instances times will often affect your placement in google and can damage your high-quality score if
    ads and marketing with Adwords. Well I’m adding this RSS to my e-mail and can look out for a lot more of
    your respective interesting content. Ensure that you update this again very soon. http://droga5.net/

    Reply
  2. 62657 217638Today, while I was at work, my sister stole my iPad and tested to see if it can survive a 30 foot drop, just so she can be a youtube sensation. My iPad is now broken and she has 83 views. I know this is entirely off topic but I had to share it with someone! 566293

    Reply

Leave a Comment