mercredi 3 juillet 2019

Find nested property from ember lodash and pick the value

I am new to javascript.

I would like to check whether the specific nested property is present or not in an array of items, ex)

[{
    "_id" : ObjectId("5c4ec057e21b840001968d31"),
    "status" : "ACTIVE",
    "customerId" : "sample-book",
    "bookInfo" : {
        "bookChunks" : [ 
            {
                "key" : "Name",
                "value" : "test"
            }, 
            {
                "key" : "Surname1",
                "value" : "testtt"
            }, 
            {
                "key" : "user-contact",
                "value" : "sample-value",
                "ContactList" : {
                    "id" : "sample-id",
                    "timeStamp" : "Tue, 20 Sep 2016 07:49:25 +0000",
                    "contacts" : [ 
                        {
                            "id" : "contact-id1",
                            "name" : "Max Muller",
                            "phone_number" : "+XXXXXXX"
                        }, 
                        {
                            "id" : "contact-id2",
                            "name" : "Max Muller",
                            "phone_number" : "+XXXXXXX"
                        }
                    ]
                }
            }
        ]
    }
},
{
    "_id" : ObjectId("5c4ec057e21b840001968d32"),
    "status" : "ACTIVE",
    "customerId" : "sample-book1",
    "bookInfo" : {
        "bookChunks" : [ 
            {
                "key" : "Name",
                "value" : "test"
            }, 
            {
                "key" : "Surname1",
                "value" : "testtt"
            }
        ]
    }
}]

Here, I would like to find whether any item has ContactList or contacts present. If it is present take the item and put it in a separate list.

I am using ember-lodash. Using normal javascript or lodash would be fine for me. Any help will be really appreciated.




Aucun commentaire:

Enregistrer un commentaire