Skip to main content

Command Palette

Search for a command to run...

Arrays in Javascript

Published
•1 min read•View as Markdown
A

I'm a developer living in Nigeria i'm 15 years old I'm open to Work And i need a Mentor And i'm a FrontEnd Developer with Experience of Over a year i'm Very fluent in English (Most Nigerians are in case you were wondering) i'm very friendly (especially towards my fellow developers) and i dislike racists and people that think of africa or Nigeria as a large forest lol

In JavaScript, array is a single variable that is used to store different elements. It is often used when we want to store list of elements and access them by a single variable.

Declaring an Array

// Arrays must be declared with brackets '[]' and each value must be seperated with commas
var myvar = [2, 4, 6, 8, 10]
// Arrays can store different values and can be mixed
var myvar = ["John Doe", 31, "Oxford University", "Full Stack Developer"]
var myvar = ["John Doe", 31, "Oxford University", "Full Stack Developer"]
console.log(myvar[0])

// The first Value in an Array is '0'
//Arrays always start from '0'

To bring out different Values

var myvar = ["John Doe", 31, "Oxford University", "Full Stack Developer"]
console.log(myvar[0, 1, 2])

/* this should bring out: John Doe, 31, Oxford University */

Arrays can be used to store information that would later be used

var myvar = ["John Doe", 31, "Oxford University", "Full Stack Developer"]
console.log("my name is " + myvar[0] ", I'm a " + myvar[3])