Font size
WorksheetsJavaScript Data Structures
Total questions: 19
Worksheet time: 10mins
If you want to be able to look up a value by an index value (4, for example) , which data structure should you choose?
array
object
set
grid
What is an Object?
An ordered list of objects
An unordered list of objects
A collection of (key, value) pairs
elements listed in a grid form
We want to make a grocery list in our program. Which of the following is the correct way to make an array/list?
var groceries = ["milk" "sugar" "eggs" "cake"];
var groceries = ["milk, sugar, eggs, cake"];
var groceries = "milk, sugar, eggs, cake";
var groceries = ["milk", "sugar", "eggs", "cake"];
What method can we use to find the index of a particular element in an array?
.index
indexOf
inIt
findElement
The index of the very first item in an array is 1.
true
false
var numbers = [0, 1, 2, 3, 4];
How can we add a 6 to the end of numbers?
pop(6)
push(6)
add(5,6)
pop( )
What is a set?
a collection of unique objects that are not in a specific order.
a collection of ordered items.
a collection of (key, value) pairs
Elements in a row and column table
Which of the options below is a set?
["hello", "goodbye"]
{"hello", "goodbye"}
{"hello", "hello", "goodbye"}
{
Jeremy: "123-4567",
Zach: "333-3333"
}
What is a Grid?
A collection of unique items with no particular order
A collection of (key, value) pairs
A collection of items each stored at a specific (row, column) location
An unordered list with unique values
What is an array ?
An unordered collection of items
An ordered collection of items
A collection of (key, value) pairs
A collection of unique objects that are not in a specific order
If you care about the order of data, data should be stored in an object.
false
true
If you want to be able to look up a value by KEY
, what data structure should you use?
object
array
grid
set
What is the output of the following program?
function start(){
var arr = [1, 2, 3, 4, 5, 6, 7];
var elem = arr.remove(2);
println(arr);
}
[1, 2, 3, 4, 5]
[3, 4, 5, 6, 7]
[1, 2, 4, 5, 6, 7]
[1, 3, 4, 5, 6, 7]
var numbers = [ 1, 2, 3, 4, 5, 6];
How can we remove the last item from the end of this array and store it in a variable called highestNum?
var highestNum = numbers.pop();
var numbers =
highestNum.push(6);
var highestNum = numbers[5];
var numbers = numbers.pop();
numCols() can tell you the number of rows in a grid.
false
true
How can we set the number for Jenny in phonebook to be "867-5309"?
phonebook["Jenny"] =
"867-5309";
phonebook["867-5309", "Jenny"];
phonebook.putJenny
("867-5309");
phonebook ["867-5309"] = "Jenny";
var shoppingList = ["milk", "eggs", "sugar", "bread", "cake"];
Which line of code will correctly change "cake" to "apples"?
shoppingList["apples"] = "cake";
shoppingList[5] = "apples";
shoppingList["cake"] = "apples";
shoppingList[4] = "apples";
What kinds of items can we store in arrays?
anything you can store in a variable
numbers only
numbers or strings of text only
strings of text only
How can we get the number for our friend Jenny out of our object phonebook and store it as a variable named number?
choose all that apply
var jenny = phonebook["Jenny"];
var number = phonebook["Jenny"];
var number = phonebook.Jenny;
var number= phonebook(Jenny);
