objects Flashcards
1
Q
describe how to retrieve values from an object (both ways)
A
objectName.property
objectName[“key”]
2
Q
what’s the syntax for updating or adding values to an object (both ways)
A
objectName.key = value; objectName["key"] = value;
3
Q
const student = { firstName : 'David', lastName : 'Jones', strengths : ['Art', 'English'], exams : { midterm1 : 92, midterm2 : 89, final : 98 } }
how would you access ‘English’?
A
student.strengths[1];
// access element in an array, nested in an object
4
Q
const student = { firstName : 'David', lastName : 'Jones', strengths : ['Art', 'English'], exams : { midterm1 : 92, midterm2 : 89, final : 98 } }
how would you access the midterm2 score, 89?
A
student.exams.midterm2;
// access value in an object, nested in another object
5
Q
const student = { firstName : 'David', lastName : 'Jones', strengths : [ ['P.E.', 'Art'], ['Science', 'English'] ], exams : { midterm1 : 92, midterm2 : 89, final : 98 } }
how would you access ‘Science’?
A
student.strengths[1][0];
// access element in a nested array, nested in an object