can any one explain me in an easy way what "hits and push" work for please?
If you define a variable
you will assign a Value to this variable
The VALUE can be anything from:
•Number •String •Boolean •Symbol •Object ◦Function ◦Array ◦Date ◦RegExp ◦Math •Null •Undefined
For each of those Data-types,
var hits = ;
your created a variable hits with a Data-type-Array being an empty Array.
If you now do a google search using
you will reach the =link=
If you open the link,
you will get the official defintion of an Array
but if you look in the left-hand-column under the header Methods
you will find a whole bunch of those Methods,
and if you want to use them, you have to follow a specific-syntax
One of those Methods, is the push()-Method
with which you are able to append new Array-Elements to an existing Array.
Thus if you would use
hits.push("A"); console.log( hits ); //=>output==> ["A"] hits.push("B"); console.log( hits ); //=>output==> ["A","B"]
In our "Search Text for Your Name"
we are going to use
hits.push( text[j] );