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

116
Views
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 answers
Answer question

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 Report

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 Report

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 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!