The string is
var str = "Beautiful Day";
I am splitting the str using white space as the separator
var substr = str.split(" ");
The above should return 2 words and so the length of the string should be 2
var strLength = substr.length;
Now, I want to pass both the words as separate parameters of a function such that:
myFunction(word1, word2)
But I don’t want to use
substr[0]
substr[1]
Since split returns an array, the apply method is perfect for you:
Edit
Since you have a variable number of arguments, you may also want to use the arguments array-like object. The above code will alert all the words in your input string, one after the other.