June 2, 2023
Program to use JavaScript String split() method
let a = "Hello World JavaScript";
let b = a.split("");
console.log(b);
Output
[
'w', 'a', 'n', 't', ' ', 't',
'o', ' ', 'c', 'o', 'd', 'e',
' ', 'j', 'a', 'v', 'a', 's',
'c', 'r', 'i', 'p', 't', ' ',
'w', 'i', 't', 'h', ' ', 'm',
'e'
]
Steps Description
- Declare two variable
a
andb
- Initialize two variable
a
andb
with value of stringa = "Hello World JavaScript";
andb
- The
split()
method converts a string into an array. - If we split a string without space with the help of split method, it will turn into a string array
- The value of
b
variable is displayed with the help of console.log inbuilt function
Program to use JavaScript String split() method
let c = "Hello World JavaScript";
let d = c.split(" ");
console.log(d);
Output
[ 'Hello', 'World', 'JavaScript' ]
Steps Description
- Declare two variable
c
andd
- Initialize two variable
c
andd
with value of stringc = "Hello World JavaScript";
andd
- The
split()
method converts a string into an array. - The value of
d
variable is displayed with the help of console.log inbuilt function
Program to use JavaScript String split() method
let e = "Hello. World. JavaScript";
let f = e.split(".");
console.log(f);
Output
[ 'Hello ', ' World ', ' JavaScript' ]
Steps Description
- Declare two variable
e
andf
- Initialize two variable
e
andf
with value of stringe = "Hello. World. JavaScript"
andf
- The
split()
method converts a string into an array. - The value of
f
variable is displayed with the help of console.log inbuilt function
Program to use JavaScript String split() method
let g = "Hello World JavaScript";
let h = g.split(" ");
console.log(h[2]);
Output
javascript
Steps Description
- Declare two variable
g
andh
- Initialize two variable
g
andh
with value of stringg = "Hello World JavaScript"
andh
- The
split()
method converts a string into an array. - The value of
h
variable is displayed with the help of console.log inbuilt function
by : Suhel Akhtar
Quick Summary:
JavaScript String split() 4 example output is different different