How to find words in a string which are greater than given length with Node.js

1 Answer

0 votes
const str = "Node.js is a cross platform  open source JavaScript runtime environment run on Windows Linux Unix macOS";
const len = 6;

let array = str.split(" ");

let words = [];

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

console.log(words);




/*
run:

[
  'Node.js',
  'platform',
  'JavaScript',
  'runtime',
  'environment',
  'Windows'
]

*/

 



answered Nov 29, 2023 by avibootz
...