Javascript split can keep splitted value?

Viewed 606

In Javascript :

var myString = "This is my string";

console.log(myString.split(/(\s)/));

Output : ["This", " ", "is", " ", "my", " ", "string"]

console.log(myString.split(/\s/));

Output : ["This", "is", "my", "string"]

Why is this happening ?

2 Answers
Related