CHAPTERTHREE
Be focused and you will archive alot. choose your ON javascript
Explore moreBe focused and you will archive alot. choose your ON javascript
Explore moreLorem ipsum dolor sit amet consectetur adipisicing elit. Hic odit rem dolorum molestiae fugit deserunt exercitationem recusandae, itaque ratione harum sit repellat dolor temporibus deleniti non voluptatem nostrum quas? Cumque veniam, molestias id natus pariatur dolores aut nemo iure facilis expedita, temporibus exercitationem ullam ex officiis reiciendis quaerat enim consequuntur.
Variables store data in JavaScript. There are three ways to declare variables:
(old, avoid using it)
(modern, used for variables that can change)
(used for variables that should not change)
An array is a list that stores multiple values inside a single variable.
Think of an array like a shopping list:
let shoppingList = ["Milk", "Bread", "Eggs"];
Creating an Array
There are two ways to create an array:
* Using Square Brackets [] (Recommended)
let fruits = ["Apple", "Banana", "Orange"];
* Using the new Array() Constructor
let numbers = new Array(1, 2, 3, 4, 5);
Accessing Array Elements
You access an array by index.
The first item is at index 0.
document.write(fruits[0]);
The second item is at index 1.
Apple document.write(fruits[1]);
Example:
let colors = ["Red", "Blue", "Green"];
colors.push("Yellow"); // ["Red","Blue", "Green", "Yellow"]
colors.pop(); // ["Red", "Blue", "Green"]
colors.unshift("Purple"); // ["Purple", "Red", "Blue", "Green"]
colors.shift(); // ["Red", "Blue", "Green"]
let animals = ["Cat", "Dog", "Rabbit"];
animals.forEach(function(animal) {
document.write(animal + "
");
});
<!DOCTYPE html> <html> <head> <title>Title of thePage</title> </head> <body> <h1>JavaScript Arrays</h1> <p id="output"></p> <script> let fruits = ["Apple", "Banana", "Orange", "Mango"]; let result = ""; fruits.forEach(function(fruit) { result += fruit + "<br>"; }); document.getElementById("output").innerHTML = result; </script> </body> </html>
Title of thePage
JavaScript Arrays
vildash network team has had alot of impact on others but here are the vildash network team testimonies and expirience while working with the team
you can now connect and text other users from our database. you just neeed to click bellow to message them
WE HAVE CODE EDITORS FOR LANGUAGES LIKE C, C#, C++, HTML, CSS, javascript, JAVA VISUAL BASIC
We dont just teach you to code we teach you to code and build amazing systems.we are group of expert who wants to promote our field of studies