Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

212
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda