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

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

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 Report

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 Report

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