Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

210
Views
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:

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?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

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

result.filter(employee => employee.area && employee.area.name === 'Vibestuen')
about 4 years ago · Juan Pablo Isaza Report

0

You can do it like this:

let vibeEmployee = result.filter(employee => employee.area && employee.area.name === 'Vibestuen')
about 4 years ago · Juan Pablo Isaza Report

0

Need to change the condition inside filter callback function. employee represents an object and area is null in few records.

Example: let vibeEmployees = data.filter( (employee) => employee.area && employee.area.name.includes("Vibestuen") );

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!