Javascript - split ()

June 2017

Strings play a very important role in programming and should be handled carefully to avoid getting any errors. Many programming languages like Strings have built in functions that help the user to modify a piece of string as per the requirements of the code. Strings has a built in split function which allows the user to subset a piece of string. Using the split function, one can extract multiple portions separately from a single piece of string.

The split () function allows you to split a string and return the results in a table, using a string defined as a separator.

In the example below, the split () can cut the date according to the character '/':

var date = '26/02/2009';  
var elem = uneDate.split('/');  
day = elem[0];  
month = elem[1];  
year = elem[2];

Related


Published by jad05. Latest update on March 3, 2012 at 11:45 AM by Celia Gatward.
This document, titled "Javascript - split ()," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).