How to find the smallest word in a string with Node.js

1 Answer

0 votes
const str = "Node.js Node.js is an open-source cross-platform server environment";
const words = str.split(" ");

let smallest = words[0];

for (let i = 0; i < words.length; i++) {
    if (words[i].length < smallest.length ) {
        smallest = words[i]
    }
}

console.log(smallest);




/*
run:

is

*/
  

 



answered Nov 12, 2022 by avibootz
...