How to print all strings from an array that ends with a given substring in TypeScript

1 Answer

0 votes
const words: string[] = ['mining', 'typescript', 'sing', 'c', 'java', "programming"]
 
const result: string[] = words.filter(w => w.endsWith('ing'))
 
result.forEach(w => console.log(w))
 

 
 
/*
run:
 
mining
sing
programming
 
*/

 



answered Dec 18, 2023 by avibootz
...