+ 1

How to get two characters from a string?

How to get two characters from a string? example: var x = "hello"; i need get two char from string => "he";

9th Apr 2022, 3:50 PM
Alexander Sokolov
Alexander Sokolov - avatar
6 Answers
+ 1
I think you can go with slice syntax .slice(start, end) So example var x = ā€œhelloā€; console.log(x.slice(0, 3));
9th Apr 2022, 3:52 PM
Faisal Issaka
Faisal Issaka - avatar
+ 1
var x = "hello"; var [y, z] = [...x]; console.log(y+z);
9th Apr 2022, 5:07 PM
CalviÕ²
CalviÕ² - avatar
0
Faisal Issaka thank u very much u saved me.
9th Apr 2022, 3:53 PM
Alexander Sokolov
Alexander Sokolov - avatar
0
You are welcome
9th Apr 2022, 4:04 PM
Faisal Issaka
Faisal Issaka - avatar
0
str.slice(0,2)
10th Apr 2022, 3:22 PM
CalviÕ²
CalviÕ² - avatar
- 2
No it's not a .slice(start, end) Its a string x = ( 0, 1)
10th Apr 2022, 3:07 PM
World Real Estate