JavaScript Built-in Method Cheat Sheet
Ever find yourself in the middle of a LeetCode problem or debugging session and think, "Wait... what methods does Map have again?" 😅
Fear not — here's your ultimate dynamic cheat sheet to inspect and remember all the built-in methods of JavaScript objects!
🔍 Inspect Methods Dynamically
Use this line to log all methods on a type:
console.log(Object.getOwnPropertyNames(Type.prototype));
Replace Type
with Array
, Map
, Set
, etc.
🧱 1. Array
console.log(Object.getOwnPropertyNames(Array.prototype));
[
"length", "constructor", "at", "concat", "copyWithin", "fill",
"find", "findIndex", "flat", "flatMap", "includes", "indexOf",
"join", "lastIndexOf", "pop", "push", "reverse", "shift",
"unshift", "slice", "sort", "splice", "toLocaleString",
"toString", "values", "keys", "entries", "forEach", "filter",
"map", "every", "some", "reduce", "reduceRight"
]
🔤 2. String
console.log(Object.getOwnPropertyNames(String.prototype));
🧰 3. Object
console.log(Object.getOwnPropertyNames(Object.prototype));
🗺️ 4. Map
console.log(Object.getOwnPropertyNames(Map.prototype));
["constructor", "clear", "delete", "get", "has", "set", "entries", "forEach", "keys", "values", "size"]
📦 5. Set
console.log(Object.getOwnPropertyNames(Set.prototype));
📆 6. Date
console.log(Object.getOwnPropertyNames(Date.prototype));
🔢 7. Number
console.log(Object.getOwnPropertyNames(Number.prototype));
🎯 8. Function
console.log(Object.getOwnPropertyNames(Function.prototype));
🧮 9. Math (not a prototype — but still useful)
console.log(Object.getOwnPropertyNames(Math));
🧬 10. JSON (also not a prototype)
console.log(Object.getOwnPropertyNames(JSON));
✅ Bonus: Create Your Own Inspector
function inspect(obj) {
return Object.getOwnPropertyNames(Object.getPrototypeOf(obj));
}
console.log(inspect([])); // For Array
console.log(inspect("hello")); // For String
console.log(inspect(new Map()));
🧠 Pro Tip
Many of these include non-enumerable methods, which is great for full discovery. If you want to get only enumerable keys:
console.log(Object.keys(Array.prototype));
Now you’ve got your very own in-browser API reference — use it like a debugger’s flashlight 🔦. Happy coding!
Top comments (0)