How to find words in a string which are greater than given length with TypeScript

1 Answer

0 votes
const str: string = "TypeScript is a free and open source high level programming language developed by Microsoft that adds static typing to JavaScript";
const len: number = 6;

let array: string[] = str.split(" ");

let words: string[] = [];

for (const s of array) {
    if (s.length > len) {
        words.push(s);
    }
}

console.log(words);




/*
run:

 ["TypeScript", "programming", "language", "developed", "Microsoft", "JavaScript"] 

*/

 



answered Nov 29, 2023 by avibootz
...