OneCompiler

[JavaScript] How to get all strings from an array that are starting with letter 'a' ?

I want to get all strings in an array that are starting with alphabet 'a', how to to do that in Javascript?

1 Answer

4 years ago by

Using filter and startsWith() methods, you can filter out the array elements which starts with letter a. For example, check the below code:

let arr = ["a", "b", "c", "d", "aa", "ab"];
console.log(arr.filter(ele=>ele.startsWith("a"))); 

Run the above code online here: https://onecompiler.com/javascript/3xn6xd62m

4 years ago by Meera