Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

To split a full name into first and last names in JavaScript

//  Supported in IE 6-11
const fullName = 'Adam Jones';

//  ['Adam', 'Jones']
const splitOnSpace = fullName.split(' ');
console.log(splitOnSpace);

const first = splitOnSpace[0];
const last = splitOnSpace[1];

console.log(first); //  Adam
console.log(last); //  Jones
Comment

PREVIOUS NEXT
Code Example
Javascript :: nginx redirect location to port 
Javascript :: two digit js' 
Javascript :: axios send post data 
Javascript :: MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 
Javascript :: remove double slash from url javascript 
Javascript :: send data from one page to another html page in Javascript 
Javascript :: how to parse using express without body parser 
Javascript :: electron open new window 
Javascript :: rect p5js 
Javascript :: javascript get nth element of array 
Javascript :: send mail with javascript 
Javascript :: javascript pushstate 
Javascript :: add class when element in viewport vanilla javascript 
Javascript :: react history go back 
Javascript :: javascript delete second last element of array 
Javascript :: crop image canvas 
Javascript :: get html input value by class name 
Javascript :: get keys of object in an array 
Javascript :: put 0 in front of month number javascript 
Javascript :: javascript check if argument is passed 
Javascript :: how to catch and throw error js 
Javascript :: javascript print random word from list 
Javascript :: get url without parameters javascript 
Javascript :: cancel button in react js 
Javascript :: jquery focus 
Javascript :: js two array combining with id 
Javascript :: js onload 
Javascript :: how to detect a url change 
Javascript :: react native slow performance after load iamges 
Javascript :: jquery validation plugin google recaptcha 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =