wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Coding Arrays

Total questions: 27

Worksheet time: 13mins

Name
Class
Date
1.

An array is:

a)

Shapes

b)

Eggs

c)

Options

d)

List of data

2.
What property tells you how many items are in an array?
a)
length
b)
count
c)
items
d)
num
3.

Why is this storage a good example of an array

a)

there are individual elements in the array

b)

there are 5 days in a week

c)

it protects the data from security risks

d)

Arrays are segmented

4.

What is first index value of an array?

a)

-1

b)

0

c)

1

d)

undefine

5.

// lockers is an array

What is lockers.length ?

a)

the number of elements in the array

b)

The height of one locker

c)

The sum of all lockers

d)

A list of long lockers

6.

Select 2 -Two are correct:

var foods = ["rice","beans","meat"];

a)

Foods is a function

b)

foods is an array

c)

foods[0] == "rice"

d)

foods[1] == "rice"

7.
Why are arrays used?
a)
Arrays store multiple data values under one name, reducing the complexity of our program
b)
Arrays store more data than if we were using variables
c)
Arrays store more data than if we were using strings
d)

to make code faster

8.

What syntax surrounds an array index zero?

a)

Parenthesis ( 0 )

b)

Curly Brackets { 0 }

c)

Angle Brackets < 0 >

d)

Square Brackets [ 0 ]

9.
How would you change the first element in an array?
a)
nums[1] = "New!";
b)
nums = "New!";
c)
var nums[1] = "New!";
d)
nums[0] = "New!";
10.

The push() method adds a new element to the end of an array

a)

true

b)

false

11.

If one week is an array, what is the index of the last day?

a)

-1

b)

0

c)

week.length

d)

week.length - 1

12.

array = [0,1,2,3,4,5,6]
// What is the length of this array?

a)

6

b)

7

c)

5

d)

0

13.

Which definition below best describe an array?

a)

An array is a function identifier that can hold more than one parameter.

b)

An array is a beam of light.

c)

An array is a special variable, which can hold more than one value at a time.

d)

An array is a special function, which can hold more than one value at a time.

14.

What is proper syntax for declaring a array in JavaScript?

a)

var foods=[ ];

b)

var foods[ ] ={ };

c)

array foods={ };

d)

obj var foods=[ ];

15.
array = [1,2,3,4,5];
What is the highest position in this array?
HINT: Remember arrays start at position 0!
a)
4
b)
5
c)
0
d)
125.7
16.

// what's the error?

var colors ["red","green","blue","dark"];

for (var i=1; i<4 ; i++) {

print( colors[ i ] );

}

a)

red never shows

b)

variable j should be used

c)

dark is not part of RGB color systems

d)

use primitive variables, not an array

17.

What loop touches all elements in this array?

var days = ["su", "m", "t", "w", "th", "f", "sa" ] ;

a)

for(var d = 0;

i <= d.length;

d++)

{ }

b)

for(var i = 0;

i < days.length;

i++)

{ }

c)

for(var i = 0;

i <= days.length;

i++)

{ }

d)

for(var i = 0;

i < i.length;

i++)

{ }

18.

days[0] is first of seven days

What is the last?

a)

days[0]

b)

days[5]

c)

days[6]

d)

days[7]

19.

// arrays are reference variables

// wallet1 is an array

clone2 = wallet1;

a)

a change to either is a change to both

b)

anyone with access to clone2 can access your wallet1

c)

You can change clone2 leaving wallet1 unchanged

d)

Both reference the same data

20.
Which of these for loops would iterate through each item of the nums array (no more, no less)?
a)
for (var i = 0; i < nums; i++) { }
b)
for (var i = 1; i < nums.length; i++) { }
c)
for (var i = 1; i < nums; i++) { }
d)
for (var i = 0; i < nums.length; i++) { }
21.

Access all array e elements backwards?

a)

for(int i = e.length - 1;

i > 0;

i--)

b)

for(int j= e.length - 1;

j >= 0;

j--)

c)

for(int k= e.length;

k> 0;

k--)

d)

for(int i= e.length;

j >= 0;

k--)

22.

What is returned by values[3]?

a)

3

b)
12
c)
6
d)

2

23.

myArray = [10,20,30,40,50]
// We call the .splice() method to delete items

// what's the result after we call splice as:
myArray.splice(0, 1);

a)

[20,30,40,50]

b)
[2,3,4,5,1]
c)

[10,20,30,40]

d)

[50,40,30,20]

24.

How do we declare 2d arrays?

// for example a chessboard?

a)

var board= [ [] ] ;

b)

var board = [ ][ ] ;

c)

var board : [ ] ;

d)

var [ ][ ] bpard;

25.

The push() method adds an element to the _______ of the array.

a)

beginning

b)

middle

c)

end

d)

none of the above

26.

The shift() method removes the first array element and "shifts" all other elements to a lower index.

a)

true

b)

false

27.

How would you access the element holding 8?

Hint, first find the row, then the column.
Two dimensions: First Y axis, then X axis.

a)

[1,2]

b)

[c2,r1]

c)

[2,3]

d)

array[8]