To explain the expression,
“var valAry = value.split(“\r”);”
This sets a variable name to the value.split(“\r”);
“value”
This is the property value, in this case, whatever text you enter.
“value.split(“\r”);”
This searches for any line breaks you have entered and split the value from a string to an Array.
An array is like a group of objects and array indexing starts from 0 instead of 1.
So if I have a basket of apples, the basket would be the Array, and the first apple would be basket[0], the second apple would be basket[1] and so on.
“var curLine = “”;”
This sets a variable name “curLine” and give it an empty string to be filled later.
“for (var i=0;i<valAry.length;i++){
//something
}”
This is generally called a for loop which I will break down more in the bottom.
“var i = 0;”
It sets a variable “i” to be 0. 0 because array indexing starts from 0.
“i<valAry.length; i++”
This sets valAry.length as the total number of loops to be done.
for example, if your text has 2 lines, valAry.length would be 2, so if i starts from 0, it would finish the loop and see if it is still smaller than valAry.length. If it is smaller, i ++ plays out and i becomes 1 now and loops again..
“curLine += i+1 + ” ” + valAry[i] +”\r”;”
This sets the string for the variable “curLine” which was set earlier.
Since i starts from 0 and I would like the first line to start from 1 instead, I added a i+1.
valAry [i] is each line of text before each line break.
“\r” is the line break.
I hope this helps you understand things more! 🙂