programming-examples/js/Functions/Write a JavaScript function that accepts a string as a parameter and find the longest word within the string..js
2019-11-15 12:59:38 +01:00

15 lines
355 B
JavaScript

function find_longest_word(str)
{
var array1 = str.match(/\w[a-z]{0,}/gi);
var result = array1[0];
for(var x = 1 ; x < array1.length ; x++)
{
if(result.length < array1[x].length)
{
result = array1[x];
}
}
return result;
}
console.log(find_longest_word('Web Development Tutorial'));