Font size
WorksheetsCoding Arrays
Total questions: 27
Worksheet time: 13mins
An array is:
Shapes
Eggs
Options
List of data
Why is this storage a good example of an array
there are individual elements in the array
there are 5 days in a week
it protects the data from security risks
Arrays are segmented
What is first index value of an array?
-1
0
1
undefine
// lockers is an array
What is lockers.length ?
the number of elements in the array
The height of one locker
The sum of all lockers
A list of long lockers
Select 2 -Two are correct:
var foods = ["rice","beans","meat"];
Foods is a function
foods is an array
foods[0] == "rice"
foods[1] == "rice"
to make code faster
What syntax surrounds an array index zero?
Parenthesis ( 0 )
Curly Brackets { 0 }
Angle Brackets < 0 >
Square Brackets [ 0 ]
The push() method adds a new element to the end of an array
true
false
If one week is an array, what is the index of the last day?
-1
0
week.length
week.length - 1
array = [0,1,2,3,4,5,6]
// What is the length of this array?
6
7
5
0
Which definition below best describe an array?
An array is a function identifier that can hold more than one parameter.
An array is a beam of light.
An array is a special variable, which can hold more than one value at a time.
An array is a special function, which can hold more than one value at a time.
What is proper syntax for declaring a array in JavaScript?
var foods=[ ];
var foods[ ] ={ };
array foods={ };
obj var foods=[ ];
What is the highest position in this array?
HINT: Remember arrays start at position 0!
// what's the error?
var colors ["red","green","blue","dark"];
for (var i=1; i<4 ; i++) {
print( colors[ i ] );
}
red never shows
variable j should be used
dark is not part of RGB color systems
use primitive variables, not an array
What loop touches all elements in this array?
var days = ["su", "m", "t", "w", "th", "f", "sa" ] ;
for(var d = 0;
i <= d.length;
d++)
{ }
for(var i = 0;
i < days.length;
i++)
{ }
for(var i = 0;
i <= days.length;
i++)
{ }
for(var i = 0;
i < i.length;
i++)
{ }
days[0] is first of seven days
What is the last?
days[0]
days[5]
days[6]
days[7]
// arrays are reference variables
// wallet1 is an array
clone2 = wallet1;
a change to either is a change to both
anyone with access to clone2 can access your wallet1
You can change clone2 leaving wallet1 unchanged
Both reference the same data
Access all array e elements backwards?
for(int i = e.length - 1;
i > 0;
i--)
for(int j= e.length - 1;
j >= 0;
j--)
for(int k= e.length;
k> 0;
k--)
for(int i= e.length;
j >= 0;
k--)
What is returned by values[3]?
3
2
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);
[20,30,40,50]
[10,20,30,40]
[50,40,30,20]
How do we declare 2d arrays?
// for example a chessboard?
var board= [ [] ] ;
var board = [ ][ ] ;
var board : [ ] ;
var [ ][ ] bpard;
The push() method adds an element to the _______ of the array.
beginning
middle
end
none of the above
The shift() method removes the first array element and "shifts" all other elements to a lower index.
true
false
How would you access the element holding 8?
Hint, first find the row, then the column.
Two dimensions: First Y axis, then X axis.
[1,2]
[c2,r1]
[2,3]
array[8]
