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

223
Visualizações
How to remove a value that contains comma in array
dataSize.map((x) => {
 if(x.indexOf >-1 !== true) {
 return x;
}
});

the output is like this ['XL', undefined, 'S', undefined] instead of ['XL', 'S']

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

0

In terms of Array.map() and Array.filter(), the former is used for manipulating array elements and the latter for filtering, or in other words, selecting particular array elements based on a condition.

When using the includes() method, a case-sensitive search is performed to determine if a string can be found within another string, returning true or false as appropriate.

const dataSize = ["XL", "M,L,XL", "S", "X,L"];
console.log(dataSize.filter((s) => !s.includes(",")));

about 4 years ago · Juan Pablo Isaza Relatório

0

You can use array filters, if the function passed in as the parameter to the filter function returns falsey, it will be removed from the array.

Your solution, with map did not work because it manipulates values, but it doesn't remove them.

const dataSizes = ['XL', 'M,L,XL', 'S', 'X,L']
const filteredDataSizes = dataSizes.filter((size) => !size.includes(","));

console.log(filteredDataSizes);

about 4 years ago · Juan Pablo Isaza Relatório

0

You can use filter to iterate the array. And a good JS function to check this would include.

const dataSize = ['XL', 'M,L,XL', 'S', 'X,L']

let n = dataSize.filter(e => !e.includes(','))

console.log(n)

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