I use split() method here in the word "Hello". I split with character "e". So i should get length 1 when i split with "e" because there is only 1 "e" in the word. But i get 2 as a result. Can anyone help me to explain what is the concept of javascript working here. The code is as follows. Thanks in advance.
var string = "Hello";
var count = string.split("e").length;
console.log(count);
CodePudding user response:
The split command is used to separate a string based on a letter key. This means that the word hello is separated by the letter key "e". Therefore, since there is no more than one (e) in the word hello, this string is divided into two parts.