1st code:
var str = "Hello";
var arr = str.split("");
var text = "";
var i;
for (i = 0; i < arr.length; i++) {
text += arr[i] + "<br>"
}
document.write(text);
2nd code: I want to implement the string method split() in the object literal code
var greeting = {
str: "Hello",
arr: str.split(""), // string method: split()
text: " ",
loop: function() {
for (var i = 0; i < this.arr.length; i++) {
this.text += this.arr[i] + "<br>"
}
document.write(this.text);
}
};
greeting.loop();
So the 2nd code would output the same as the 1st code