Answers for "8.3.1. Common Array Methods // split Examples (.split)"

0

8.3.1. Common Array Methods // split Examples (.split)

//The general syntax for this method is:
stringName.split('delimiter')

/*split is actually a string method, but it complements the array 
method join.

split divides a string into smaller pieces, which are stored in a 
new array. The delimiter argument determines how the string is broken 
apart.*/

let numbers = "1,2,3,4";
let word = "Rutabaga";
let phrase = "Bookkeeper of balloons."
let arr = [];

arr = numbers.split(',');  //split the string at each comma.
console.log(arr);

arr = phrase.split(' ');   //split the string at each space.
console.log(arr);

arr = word.split('');      //split the string at each character.
console.log(arr);

//['1', '2', '3', '4']
//['Bookkeeper', 'of', 'balloons.']
//['R', 'u', 't', 'a', 'b', 'a', 'g', 'a']
Posted by: Guest on June-16-2021

Code answers related to "8.3.1. Common Array Methods // split Examples (.split)"

Code answers related to "Javascript"

Browse Popular Code Answers by Language