<html> <body> <script language="javascript"> function function1(){ var myString = 'Sample String 1 2 3'; var myArray = myString.split(' '); alert(myArray.length); } </script> <button onclick="function1();">SPLIT</button> </body> </html>