push and pop Method (Array) (JavaScript)

The push method can be used to add values to the end of an array. The popmethod does the opposite: it removes the value at the end of the array and returns it. An array of strings can be flattened to a single string with the joinmethod. The argument given to join determines the text that is glued between the array’s elements.



var mack = [];mack.push("Mack");mack.push("the", "Knife");console.log(mack);// → ["Mack", "the", "Knife"]console.log(mack.join(" "));// → Mack the Knifeconsole.log(mack.pop());// → Knifeconsole.log(mack);// → ["Mack", "the"]



Source: http://eloquentjavascript.net/04_data.html
Previous Post Next Post