1 Star2 Stars3 Stars4 Stars5 Stars (17 votes, average: 5.00 out of 5)

JavaScript Array Methods For Absolute Beginners

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.

Tip: Click on images to make them larger. If you find anything wrong on this page or need further assistance please comment below or contact me. 🙂
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.

Subscribe To My YouTube Channel:

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 Poped Out

There is also a way to return the item that was poped out.

See Pop Method Here

Complete Set Of JavaScript Methods

Next Lesson

JavaScript Array Methods For Absolute Beginners was last modified: June 28th, 2017 by Maximus Mccullough

Please like, share and subscribe.

Advanced Programming Made Easy

I hope you enjoyed the article. If I was able to help you please consider a tip for the content.

One Time Tip

more tips

Reoccuring Tips


Cool People Share:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.