Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

115
Vistas
remove sepcific items from array of strings javascript

i have an array that is

const arr = ["a","b","c","d","e"]

I need to exclude a,b that is I need. How to achieve this in fastest possible way

["c","d","e"]

about 4 years ago · Santiago Gelvez
3 Respuestas
Responde la pregunta

0

Using array.filter() we can do it. like:

arr = ["a","b","c","d","e"];
arr.filter(x => x !== 'a'); // output: ['b', 'c', 'd', 'e']

But if you want to remove a group of items then use another array and use validation with in filter() function.

Example:

arr = ["a","b","c","d","e"];
removeItems = ['a', 'b'];
arr.filter(x => removeItems.indexOf(x) < 0); // ['c', 'd', 'e']

enter image description here

about 4 years ago · Santiago Gelvez Denunciar

0

You can use this, if I understand it correctly

arr.filter((value) => value != 'a' && value != 'b')

gives below output

['c', 'd', 'e']
about 4 years ago · Santiago Gelvez Denunciar

0

you can do it in 1 line using spread operator

   const [one,two,three,...rest]=arr;

   console.log(rest); // it prints d,e excluding a,b,c.
about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda