How to create a tree (parent-child) object from Array in Javascript
问题 I have an array like [ "parent1|child1|subChild1", "parent1|child1|subChild2", "parent|child2|subChild1", "parent1|child2|subChild2", "parent2|child1|subChild1", "parent2|child1|subChild2", "parent2|child2|subChild1", . . . ] Wherein my first string before | is the parent and the second string before | is the child and the third string after the second | is the subchild How can I convert this array into an object like [ { "id": "parent1", "children":[ { "id": "child1", "children":[ { "id":