I am trying to sort out list elements that starts with 'N' into a new list. Why won't this work?
const countries = ['Norway', 'Sweden', 'Denmark', 'New Zealand'];
function firstN(){
for (let i=0;i<countries.length;i++){
countries[i].startsWith("N")
}
}
let startsWithN = countries.filter(firstN())
const freinds = ['Salman', 'Asad', 'Shahrukh', 'Aman'];
const startsS = freinds.filter((freind) => freind.startsWith("s"));
console.log(startsS);
Output:
[ 'Salman', 'Shahrukh' ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With