var s = 'qwye r2ty qwww ert efger'; var myArray = s.split(' '); sm = myArray[0]; for (var j=1; j<myArray.length; j++) { if (myArray[j].length<sm.length) { sm=myArray[j]; } } alert(sm)