Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TypeError: employee.includes is not a function

I got the following objects. I want to filter them in javascript, and get alle the objects with the area name of "Vibestuen".

[
        {
            "id": 292,
            "name": "Hans",
            "image": "as",
            "calculatedVacation": 1.0,
            "area": {
                "name": "Ikke tilknyttet en stue"
            }
        },
        {
            "id": 295,
            "name": "xx",
            "image": "zz",
            "calculatedVacation": 2.0,
            "area": {
                "name": "Vibestuen"
            }
        },
        {
            "id": 296,
            "name": "xx",
            "image": "abccc.png",
            "calculatedVacation": 2.0,
            "area": {
                "name": "Andestuen"
            }
        },
        {
            "id": 298,
            "name": "bunun",
            "image": "zz",
            "calculatedVacation": 2.0,
            "area": null
        },
        {
            "id": 299,
            "name": "lort",
            "image": "kol",
            "calculatedVacation": 2.0,
            "area": {
                "name": "Vibestuen"
            }
        }
    ]

Currently my javascript looks as follows:

fetch(baseURL + "/employees")
.then(response => response.json())
.then(result => {
    let vibeEmployees = result.filter(employee => employee.includes('Vibestuen'));

    console.log(vibeEmployees)
})

Im getting the following error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Uncaught (in promise) TypeError: employee.includes is not a function
at showEmployeeVibe.js:4
at Array.filter (<anonymous>)
at showEmployeeVibe.js:4

How do i filter these objects?

>Solution :

includes check if parameter is contained on Array. You filter should look like this

result.filter(employee => employee.area && employee.area.name === 'Vibestuen')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading