Javascript examples for String:split
Use the limit parameter:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from ww w. j a v a 2 s .c om var str = "The following code shows how to ?"; var res = str.split(" ", 3); document.getElementById("demo").innerHTML = res; } </script> </body> </html>