
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
- Related Questions & Answers
- Constructing full name from first name, last name and optional middle name in JavaScript
- Validate the first name and last name with Java Regular Expressions
- MySQL query to display columns name first name, last name as full name in a single column?
- MySQL GROUP BY and CONCAT() to display distinct first and last name
- How to recognize full name and last name in Open NLP?
- How to create separate columns for first and last name in R?
- Display records where first and last name begins with the same letter in MySQL
- Searching 2 fields at the same time to fetch a specific First Name and Last Name from a table in MySQL
- Select Statement to retrieve the same first names with similar last name (but different case) using MySQL?
- JavaScript Error name Property
- How to separate last name and first names in single column into two new columns in MySQL?
- Python program to print the initials of a name with last name in full?
- Java program to print the initials of a name with last name in full
- Node name of an HTML element using javascript?
- Get the first and last item in an array using JavaScript?
Advertisements