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