June 6, 2023
Program to use JavaScript String slice()
let a = 'Hello World JavaScript';
let b = a.slice(0, 11);
console.log(b);
Output
Hello World
Steps Description
- Declare two variable
a
andb
- Initialize two variable
a
andb
with value of stringa = 'Hello World JavaScript'
andb = a.slice(0, 11)
- String
slice()
method String can be sliced by giving statement - The value of
b
variable is displayed with the help of console.log inbuilt function
Program to use JavaScript String slice()
let c = 'Hello World JavaScript';
let d = c.slice(11, 22);
console.log(c.length);
console.log(d);
Output
22
JavaScript
Steps Description
- Declare two variable
c
andd
- Initialize two variable
c
andd
with value of stringc = 'Hello World JavaScript'
andd = c.slice(11, 22)
- String
slice()
method String can be sliced by giving statement - The value of
d
variable is displayed with the help of console.log inbuilt function
by : Suhel Akhtar
Quick Summary:
JavaScript String slice()