I am new to javaScript and is not able to understand why split function is behaving differently just by assigning it to a variable.
For example,
var str = "This is text 1";
var ani = str.split(" ");
console.log(ani[0]);
The above code gives the whole word "this" , whereas for the below code
var str = "This is text 1";
str.split(" ");
console.log(str[0]);
It gives result as the first character of the string.
Why didn't the later code result was same to the first one?
splitdoes not modify the string being split.str.split(" ");to anything. You should save ti likelet anyother = str.split(" ");