Multiple choice

What will be the output of the above code snippet?

var str=This is a sample string;
var output=str.split(,);
document.write(output);

  1. Compilation Error

  2. This,is,a,sample,string

  3. This,is,a,sample,string,

  4. ,This,is,a,sample,string,

  5. T,h,i,s,i,s,a,s,a,m,p,l,e,s,t,r,i,n,g

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The split() method is used to split a string into an array of substrings, and returns the new array. In the above code, the spaces of the string will be converted to commas (,)