Find by key deep in a nested array

后端 未结 17 1497
礼貌的吻别
礼貌的吻别 2020-11-22 15:41

Let\'s say I have an object:

[
    {
        \'title\': \"some title\"
        \'channel_id\':\'123we\'
        \'options\': [
                    {
                 


        
17条回答
  •  不要未来只要你来
    2020-11-22 16:06

    I've created library for this purpose: https://github.com/dominik791/obj-traverse

    You can use findFirst() method like this:

    var foundObject = findFirst(rootObject, 'options', { 'id': '1' });
    

    And now foundObject variable stores a reference to the object that you're looking for.

提交回复
热议问题