+ 2

How to Split String in js

16th Apr 2021, 1:22 PM
Hisham Abdelgadir Mohamed
Hisham Abdelgadir Mohamed - avatar
6 Réponses
+ 3
let str = 'Koanti'.split(''); // splits by each letter let str_1 = 'K,oanti'.split(','); // split by comma let str_2 = [...'Koanti']; // iterate it for unicode in modern browser and 2015+ non-IE supported
16th Apr 2021, 2:00 PM
Basel.Al_hajeri?.MBH()
Basel.Al_hajeri?.MBH() - avatar
+ 3
CamelBeatsSnake it won't be split it would be str.split() => [str]
16th Apr 2021, 2:03 PM
Basel.Al_hajeri?.MBH()
Basel.Al_hajeri?.MBH() - avatar
+ 3
#ohh and in python print('How are you'.split(' ')) or print([i for i in 'hello']) # ['How', 'are', 'you'] then ['h',...,'o']
16th Apr 2021, 2:10 PM
Basel.Al_hajeri?.MBH()
Basel.Al_hajeri?.MBH() - avatar
+ 2
Basel.Al_hajeri?.MBH() Thanks. I made a little mistake.
16th Apr 2021, 2:34 PM
CamelBeatsSnake
CamelBeatsSnake - avatar
+ 1
const splitStr = "a string".split(" ") // splitStr is now an array: ["a", "string"] The separator you pass into split(yourSeparator) is optional. This can be a string or a regular expression.
16th Apr 2021, 1:28 PM
CamelBeatsSnake
CamelBeatsSnake - avatar
+ 1
# if String is text or have space word='hello world !' word=word.split() print(word) #if is one word a='hello' b=[] for i in a: b.append(i) print(b) c='hello' d=[i for i in c] print(d) #For specific tasks you must write function
16th Apr 2021, 2:06 PM
Amir
Amir - avatar