0

hope you can help me:

i try to get all the user who have the techno name on their abilities.

my json object look like (fake data): `

[
    {
        "name": "Thomas",
        "firstname": "pardou",
        "job": "Backend developer",
        "technos": [
            {
                "name": "Javascript",
                "appreciation": "Beginner"
            },
            {
                "name": "Php",
                "appreciation": "Expert"
            },
            {
                "name": "Ruby",
                "appreciation": "Regular"
            },
            {
                "name": "Scrum",
                "appreciation": "Ignore"
            },
            {
                "name": "Démarchage",
                "appreciation": "Guru"
            }
        ],
        "missions": [
            [
                {
                    "name": "Backend Developer"
                },
                {
                    "name": "Product Owner"
                }
            ]
        ],
        "createdAt": "2022-12-22T11:46:08.193Z",
        "updatedAt": "2022-12-22T11:46:08.193Z",
        "id": "63a44380da6f96d105b6d86b"
    }
]

i try to di it with :

    let filteredData = userData.filter(e => e.technos.name === data.name)

anyone can help me with a solution ? thanks

Tamir Abutbul
  • 7,301
  • 7
  • 25
  • 53
Virgile J
  • 1
  • 1
  • `technos` is an array, so you'll need to use `some()` inside the `filter` since you want it to be included if 'some' of those objects have maching names – 0stone0 Dec 22 '22 at 13:50
  • [There's no such thing as a "JSON Object"](https://benalman.com/news/2010/03/theres-no-such-thing-as-a-json/) – Andreas Dec 22 '22 at 13:50
  • Does this answer your question? [Sort array of objects by string property value](https://stackoverflow.com/questions/1129216/sort-array-of-objects-by-string-property-value) – Bani Dec 22 '22 at 13:52
  • OP want's to filter, not sort @Bani – 0stone0 Dec 22 '22 at 13:53
  • `userData.filter(e => e.technos.some(t => t.name === data.name))` To get all the user objects where they have a techno object with `name === data.name` – adiga Dec 22 '22 at 13:58

0 Answers0