Hit.push


#1

Please, i need someone to quickly explain to me how hit.push works
Thank you.


#2

.push() is a method applicable to any array which appends a new element to it.

var text = "Some text";
var hits = [1, "Hi"];
var j = 2;
hits.push(text[j]);
// hits is the array which the method is applied to
// .push() is the method which would append a new element to the array
// text[j] is the value of the element we want to append
// it takes the jth letter of the "text" variable (remember computers count from 0)

// now the "hits" array contains three elements which are 1, "Hi" and "m"

#3

thanks a million maxtirdatov