Array Demo

1D Arrays

Overview

The demo below allows you to simulate a 1-dimensional array. You can select whichever language you are working with from the dropdown box.

Which Language Are You Working With?

A Few Things to Remember

  1. The location of an item in an array is called an index, or indices plural.
  2. The first item in an array is at index 0. The last item is at the index that is one less than the length of the array (e.g. an array of 8 items would have indices from 0 to 7).
  3. The items in an array can be of any type; they are not limited to the four basic options provided in this tool (integer, double, string, and boolean). However, every item in the array must be of that same single type.
  4. The language you selected in the dropdown above will not impact the behavior of the array; it simply helps guide how you put your array into code.

Creating an Array

In order to use an array, you first must create and initialize it. In the section directly below, specify a few important properties of the array.

Creating & Initializing

Item Type:

Arrays may contain many different values. However, every item in the array must be of the same type. For example, you can't have an array containing both numbers and words.

Name:

Give the array a name. This will not impact how the array actually works, it will just help you keep track of it in your code.

Initialization Method:
Size:
Values: Please separate values with only a comma and no spaces

Finally, initialize the array. This determines what the values in the array will look like when it is first created. You can either specify a certain number of "empty" default values or choose to specify each value literally.

What the Code Looks Like:
									
										IF YOU CAN SEE THIS THERE IS A JAVASCRIPT ERROR (Try reloading the page I guess) :(
									
								

This is what the code looks like to create and initialize the array in your selected language using the properties you specified.

At this time there is no built-in syntax error detection for some features of this tool. If you make syntactic mistakes this tool may not alert you of the mistake. Please keep this in mind and type carefully.

Current Array

The table below gives a live look at the current array you just created using the properties you specified above. Feel free to go back and change those properties at any time, however note that those changes may reinitialize the values currently stored in the array (clearing them).

Each index (location in the array) has a value below it. Use the sections below the table to read the value of specific items and modify the value of items. When you read or set an item, the index and the value will be highlighted in red to show where the action took place.

Click this button to reset the array contents back to the initialized values.

IF YOU CAN SEE THIS THERE IS A JAVASCRIPT ERROR (Try reloading the page I guess) :(
Scroll to see more values if they exceeed the width of the display.

Getting A Specific Value

Index:
Output:

The value of the item at the index you specified will be read and outputted. For example, if the item at index 3 contains the number 21, reading from index 3 will output "21".

What the Code Looks Like:
									
										IF YOU CAN SEE THIS THERE IS A JAVASCRIPT ERROR (Try reloading the page I guess) :(
									
								

This is what the code looks like to read a value from the array in your selected language. Note that we are also adding a print statement to display the value.

Setting A Specific Value

Index:
Value:

The value at the index you specified will be changed to the new value you provided.

What the Code Looks Like:
									
										IF YOU CAN SEE THIS THERE IS A JAVASCRIPT ERROR (Try reloading the page I guess) :(
									
								

This is what the code looks like to set a value in the array in your selected language.