It’s syntax look like –
In the next step, we create an another variable array using let and assign an array return from string split method.
let array = string.split(“s”);
As you can see, we pass a substring “s” as a separator. Now finally, we are checking the length of the array. Any guess, what should be the output.
Now, you know the answer is 2 but why as we can see there are three “s” in the sting. Then the answer should be 3 or either 4 but not 2.
Let me explain –
[“Java”, “cript (JS) Startup”]
At last, That’s why we get an answer “2“.
I hope you understand the concept and logic behind it.
But wait, i have something more for you –
- JS Quiz – variable can be key and value in object
- JS Quiz – var in a block scope work
And last but not the least, don’t forget to like, comment and share. It gives us a morale boost to remain to continue. Also, join our Facebook Page
If you have any questions, please feel free to ask me in the comment section and also let me know if you have any suggestions. As suggestions are always welcome.