JavaScript Program to Split Name Using String's split() Method

Write a JavaScript program to split name using string's split() method.



Source Code
<html>
<head>
    <title>Manipulating a String</title>
</head>
<body>
<script>
    var name = prompt('Enter ur name');
    var text = name.split(' ');
    document.write('First name: ' + text[0] + "<br/>");
    document.write('Last name: ' + text[1]);
</script>
</body>
</html>
Output





"Coding Hub - Learn to code" app now available on Google Play Store