JSFiddle - React, Tailwind, and code Playground

by Slava Slava

JavaScript

function getChildLists(list, name) {
  for(let i = 0; i < list.length; i++) {

    if(list[i].name === name) {
      return list; // вернуть результат. Всегда undefined
    }
    // рекурсивно искать совпадения
    if(list[i].children) {
      return getChildLists(list[i].children, name);
    }
  }
}

let wrapper = getChildLists(lists, 'категория 1'); 

console.log(wrapper); // undefined