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

82
Visualizações
Return all objects within an array based on if they contain a portion of a string

[
  {
    "population": 121321313,
    "location": "American city in the East"
  },
  {
    "population": 54646546,
    "location": "Canadian city in the East"
  },
  {
    "population": 6546467,
    "location": "American city in the West"
  },
  {
    "population": 145313,
    "location": "American city in the South"
  },
  {
    "population": 12673,
    "location": "Canadian city2 in the East"
  },
  {
    "population": 141313,
    "location": "Canadian city in the South"
  },
  {
    "population": 1264473,
    "location": "Canadian city4 in the East"
  },
  {
    "population": 12673,
    "location": "Canadian city6 in the South"
  }
  
]

I'm trying to figure out how to filter out all the objects within the array based on whether their location is American or Canadian and by Region (East, West, South).

For example, if I want all Canadian cities in the East it would return objects with the index of 1,4,6. How would you filter out the location string within the array based on two parameters, whether they contain American or Candian and East, West, South.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Hopefully the following example will put you on the right track

Assumption: your array is stored in a variable named data

var searchString = "American";
var filteredData = data.filter((item) => {
    return item.location.includes(searchString);
});
for (var i = 0; i < filteredData.length; i++) {
    console.log(filteredData[i].location);
}

Fabio

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