What does hits.push() actually do?


#1

In the "Search Text for Your Name" section, I am not entirely sure what hits.push() actually does. The explanation does not make sense to me. My current code is below. The tutorial tells me that I should use hits.push() in some way but I am not even sure what it would do to my existing code!

I currently understand how to write code for the program to search the text and then once it hits a "J" to keep on going until it finds a word starting with "J" with the same letter count as "Jennifer"

var text = "I cannot believe that you did this Jennifer. /
What are you doing? I am disappointed with you, Jennifer";
var myName = "Jennifer";
var hits = [];

for (var i=0; i < text.length; i++) { 
    if (text[i] === "J"  {
    for (var j=i; j < (myName.length+i); j++) { 
    }
    }
}

#2

You forgot to delimit your conditional expression of the if's statement with ).

push() method?
You can use it on array to add items at the end of the array.
You can either add one or more items at one time.

var x = [1,2,3];
x.push("a");
x.push(true,false,"hey")

console.log(x) // prints [1, 2, 3, "a", true, false, "hey"]

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.