JavaScript Code:
const str = " ";//5 spaces
const strSplit = str.split("");
const strSplitWithSpace = str.split(" ");
console.log(strSplit); //[ ' ', ' ', ' ', ' ', ' ' ]
console.log(strSplitWithSpace);//[ '', '', '', '', '', '' ]
console.log(strSplit.length);// 5
console.log(strSplitWithSpace.length);// 6
Question:
Why will JavaScript treat " "
string like that
when method .split()
with separator " "
is applied to it?
The length of the created array is longer than the one with no separator…
Can anybody explain?