Saturday Flashcards
(5 cards)
Object constructor methods
assign
entries
keys
values
hasOwnProperty
assign —
entries —
keys —- returns the keys in an object in an array as string elements
values — returns the values in an object in an array
hasOwnProperty —- a method that checks for the presence of a key (passed in as an argument) & returns a boolean
describe three ways to enumerate an object
for…in loop
for (let nameRepresentingEachKey of objectName) {
body
};
for…of loop with Object methods
for (let [key, value] of Object.entries(objName)) **
for (let value of Object.values(objName)) **
for (let key of Object.keys(objName))
array method with Object methods
Object.keys(obj).forEach(key => { functionality });
*** remember that keys are automatically stored as strings when pulled from an object literal… if you need to act on or pass the numeric version of a key (if keys are numbers in the object), you have to convert the number (or variable holding the number) to a string value using parseInt function
array methods
forEach
map
find max (not using Math methods) and min (using Math method) using reduce
const grades = [87, 64, 96, 92, 88, 99, 73, 70, 64];
const maxGrade = grades.reduce ((max, currVal) => {
if(currVal > max) return currVal;
return max;
});
console.log(maxGrade)
ORRRRR
const maxGrade = grades.reduce((max, currVal) => max > currVal ? max : currVal);
console.log(maxGrade);
const minGrade = grades.reduce ((min, currVal) => {
return Math.min(min, currVal);
});
console.log(minGrade);
pass by value vs pass by reference