Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Split First name and Last name using JavaScript?
Let’s say the following is our string with name −
var studentFullName="John Smith";
Use split() to split the first name and last name. Following is the code −
Example
var studentFullName="John Smith";
var details=[]
var details=studentFullName.split(' ');
console.log("StudentFirstName="+details[0])
console.log("StudentLastName="+details[1]);
To run the above program, you need to use the following command −
node fileName.js.
Output
Here, my file name is demo163.js. This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo163.js StudentFirstName=John StudentLastName=Smith
Advertisements
