js find longest word in string function
function findLongestWordLength(str) {
return Math.max(...str.split(' ').map(word => word.length));
} function findLongestWordLength(str) {
let words = str.split(' ');
let maxLength = 0;
for (let i = 0; i < words.length; i++) {
if (words[i].length > maxLength) {
maxLength = words[i].length;
}
}
return maxLength;
}
findLongestWordLength("The quick brown fox jumped over the lazy dog");
// 6
Also in JavaScript:
- calculate log in javascript
- DECIMAL TO BINARY CONVERSION javascript
- how to access array datat in class component react
- beautiful day at the movies hackerrank solution
- get string value of boolean javascript
- jquery AND operation
- button not clicking for random jokes in javascript
- settimeout es6
- regular expression
- add class when element in viewport vanilla javascript
- javascript regex .test
- jquery when iframe is loaded
- JavaScript and HTML DOM Reference
- node map has value
- jquery plugin boielr plate
- electron remove default menu
- qr code generator with javascript
- pdf to image javascript
- discord.js
- How do you detect whether or not a word is a palindrome in javascript
- jquery google cdn
- box shadow javascript style change
- javascript generate random number
- react native pm ERR! code EINTEGRITY