How to get unique objects from objects array in javascript

后端 未结 4 1433
鱼传尺愫
鱼传尺愫 2021-01-29 13:59

I have an array of objects that looks like the image below. Is there a way by which I can have an array that contains unique objects with respect to id ? We can

4条回答
  •  借酒劲吻你
    2021-01-29 14:28

    The best way to do this is to modify your data structure into an object itself where each key is one of the IDs:

    {
        "WadWA7WA6WAaWAdWA...": {
            "text": "birla"
        },
        "WadWA...": {
            "test": "ab"
        }
    }
    

    and so forth. If the data comes from a source formatted that way, you can always map the array of results to this format.

提交回复
热议问题