GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — javascript/arrays/indices.md at master · front2psy/javascript

Expand file tree

/

indices.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
34 lines (30 loc) · 1.13 KB
/

indices.md

Copy path

File metadata and controls

34 lines (30 loc) · 1.13 KB
Raw
Copy raw file
Download raw file
Edit and raw actions

Indices

So you have your array of data elements, but what if you want to access a specific element? That is where indices come in. An index refers to a spot in the array. indices logically progress one by one, but it should be noted that the first index in an array is 0, as it is in most languages. Brackets [] are used to signify you are referring to an index of an array.

// This is an array of strings
var fruits = ["apple", "banana", "pineapple", "strawberry"];

// We set the variable banana to the value of the second element of
// the fruits array. Remember that indices start at 0, so 1 is the
// second element. Result: banana = "banana"
var banana = fruits[1];

{% exercise %} Define the variables using the indices of the array {% initial %} var cars = ["Mazda", "Honda", "Chevy", "Ford"] var honda = var ford = var chevy = var mazda = {% solution %} var cars = ["Mazda", "Honda", "Chevy", "Ford"] var honda = cars[1]; var ford = cars[3]; var chevy = cars[2]; var mazda = cars[0]; {% validation %} assert(honda === "Honda"); assert(ford === "Ford"); assert(chevy === "Chevy"); assert(mazda === "Mazda"); {% endexercise %}

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.