Arrays
arr.reduce((total, value) => total + value, 0);
var names = ["Alice", "Bob", "Tiff", "Bruce", "Alice"];
var countedNames = names.reduce(function (allNames, name) {
if (name in allNames) {
allNames[name]++;
} else {
allNames[name] = 1;
}
return allNames;
}, {});
Objects
Object.keys(objectName);
Measuring Elements
- For total amount of space an item takes up, including visible content, padding, and border:
offsetWidth / offsetHeight
- For amount of space the content takes up, including padding and visible content but nothing else:
clientWidth / clientHeight
- For the total size of the content, no matter how much is visible:
scrollWidth / scrollHeight