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

100
Views
Filtering a set of letters from an array in Javascript

I am trying to extract some vowels from an array using the .filte() method but the code doesn't continue on the next letters after finding instances of the first letter.The expected output is ['a','a','i'] but it only shows ['a','a'] Here is the code

function vowelsAndConsonants(s) {
  const letters = s.toString().split("");
  console.log(letters);

  let vowels = letters.filter((letter) => {
    return letter.includes("a", "e", "i", "o", "u");
  });

  console.log(vowels);
}

vowelsAndConsonants("javascript");

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Here's one way of getting the vowels

function vowelsAndConsonants(s) {
  const letters = s.toString().split("");

  let vowels = letters.filter((letter) => {
    return ['a', 'e', 'i', 'o', 'u'].indexOf(letter) !== -1
  });

  console.log(vowels);
}

vowelsAndConsonants("javascript");

about 4 years ago · Juan Pablo Isaza Report

0

The include method can only have one argument, see this website, the easiest way to test is by testing the value with an if :

const vowels = letters.filter((letter) => {
    if (letter === "a" || letter === "e" || letter === "i" || letter === "o" || letter === "u" || letter === "y") 
        return (letter);
    return("");
});
about 4 years ago · Juan Pablo Isaza Report

0

You could also use Regular Expression.

function vowelsAndConsonants(s) {
    const letters = s.toString().split("");
    console.log(letters);
  
    let vowels = letters.filter((letter) => {
        return /[aeiou]/.test(letter);
    });
  
    console.log(vowels);
    }
  
vowelsAndConsonants("javascript");

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!