Traverse all the Nodes of a JSON Object Tree with JavaScript

前端 未结 16 1661
猫巷女王i
猫巷女王i 2020-11-22 06:26

I\'d like to traverse a JSON object tree, but cannot find any library for that. It doesn\'t seem difficult but it feels like reinventing the wheel.

In XML there are

16条回答
  •  深忆病人
    2020-11-22 07:05

    The best solution for me was the following:

    simple and without using any framework

        var doSomethingForAll = function (arg) {
           if (arg != undefined && arg.length > 0) {
                arg.map(function (item) {
                      // do something for item
                      doSomethingForAll (item.subitem)
                 });
            }
         }
    

提交回复
热议问题