Hey everybody I want to let you know that I have undertaken the grueling task of getting the heck away from WordPress. I was so sick of the problems and updates I had to do all the time. I am now using my ezbloo system and I am integrating all my old posts into the new system. It sucks, but in the end, I will save bundles of time. I needed to keep things simple and that is why I created ezbloo. I'll have more on this later for you guys after I am done with the total integration of my old posts here. So if you are looking for a post and need it faster, shoot me an email and I will make it a priority. [email protected]


There are JavaScript methods that you can take advantage of when you need to. We like to propose applications where you can use such methods. This helps you to understand them better. In this lesson today we are going to use a JavaScript method of push to show a random number.

Set The JavaScript Array

Lets set up the JavaScript array. We are going to use an example of the Power Ball Lottery. This consists of 6 numbers total. The first 5 numbers are 1 through 69. However the last number is 1 through 26. We are going to set up the first 5 numbers for our array.
var lucky = ["11", "25", "33", "42", "57"];

Generate a Random Number Math Function In JavaScript

To generate a random number from 1 to 26 we will use this JavaScript function stored in a variable called rand.
var rand = Math.floor(Math.random() * 26) + 1;

Use Push() Method To Add Final Number

Use the push method to add the final number to the array. This will be a number auto generated 1-26. Here is the syntax.
lucky.push(rand);
Try It Here

Join Method With JavaScript Arrays

You can use the join method to input something between each data item in your array.
var fruits = ["Tom", "Dick", "Harry"];
var x = document.getElementById("foo")
x.innerHTML = fruits.join(" / ");
See Join Method Here

Pop Method in JavaScript

Use the pop method when you want to remove the last item in the array. See Pop Method Here

Return Items Popped Out

There is also a way to return the item that was popped out. See Pop Method Here Complete Set Of JavaScript Methods Next Lesson