Stack Overflow Collections
Table of Content
- JavaScript
- How to display all methods of an object? (206 votes)
- Get the name of an object’s type (1027 votes)
- A function to print prototype chain for a given object (9 votes)
- Plain object is not iterable (57 votes)
- TC39 Process (96 votes)
arguments
alternative in ES6 arrow functions (33 votes)Array.prototype.map
not working on an array of empty slots (152 votes)- How do I test for an empty JavaScript object?
- Spread Syntax vs Rest Parameter in ES2015 / ES6
- Get the last item in an array (761 votes)
- What does
void 0
mean? (1091 votes) - Copy array by value (1424 votes)
- What is the most efficient way to deep clone an object in JavaScript? (4701 votes)
JavaScript
https://stackoverflow.com/questions/tagged/javascript?sort=votes&pageSize=15
How to display all methods of an object? (206 votes)
https://stackoverflow.com/questions/2257993/how-to-display-all-methods-of-an-object
//
Object.getOwnPropertyNames(Array)
// (6) ["length", "name", "prototype", "isArray", "from", "of"]
Object.getOwnPropertyNames([])
// ["length"]
Object.getOwnPropertyNames(Array.prototype)
// (31) ["length", "constructor", "concat", "find", "findIndex", "pop", "push", "shift", "unshift", "slice", "splice", "includes", "indexOf", "keys", "entries", "forEach", "filter", "map", "every", "some", "reduce", "reduceRight", "toString", "toLocaleString", "join", "reverse", "sort", "lastIndexOf", "copyWithin", "fill", "values"]
Get the name of an object’s type (1027 votes)
https://stackoverflow.com/questions/332422/get-the-name-of-an-objects-type
A function to print prototype chain for a given object (9 votes)
https://stackoverflow.com/questions/22168033/a-function-to-print-prototype-chain-for-a-given-object
A tool for visualizing and experimenting with JavaScript object relationships: http://www.objectplayground.com/
Plain object is not iterable (57 votes)
var obj = {aa: 'bb', cc: 'dd'}
// undefined
[...obj]
// VM514:1 Uncaught TypeError: obj is not iterable
// at <anonymous>:1:5
TC39 Process (96 votes)
arguments
alternative in ES6 arrow functions (33 votes)
https://stackoverflow.com/questions/41731854/why-do-arrow-functions-not-have-the-arguments-array
-
An ES5 polyfill of
Array.of()
` : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of#Polyfillif (!Array.of) { Array.of = function() { return Array.prototype.slice.call(arguments); }; }
also as:
const arrayOf = (...args) => [].slice.call(args); let result = arrayOf(1,3, 5) console.log(result)
Array.prototype.map
not working on an array of empty slots (152 votes)
https://stackoverflow.com/questions/5501581/javascript-new-arrayn-and-array-prototype-map-weirdness
arrayLength
: If the only argument passed to the Array constructor is an integer between 0 and 232-1 (inclusive), this returns a new JavaScript array with its length property set to that number (Note: this implies an array of arrayLength empty slots, not slots with actual undefined values). If the argument is any other number, a RangeError exception is thrown.
let arr1 = []; arr1.length = 5;
// (5) [empty × 5]
let arr2 = new Array(5)
// (5) [empty × 5]
let arr3 = new Array(5).fill(undefined)
// (5) [undefined, undefined, undefined, undefined, undefined]
How do I test for an empty JavaScript object?
https://stackoverflow.com/questions/679915/how-do-i-test-for-an-empty-javascript-object
Spread Syntax vs Rest Parameter in ES2015 / ES6
https://stackoverflow.com/questions/33898512/spread-syntax-vs-rest-parameter-in-es2015-es6
Get the last item in an array (761 votes)
https://stackoverflow.com/questions/3216013/get-the-last-item-in-an-array https://stackoverflow.com/questions/33064377/destructuring-to-get-the-last-element-of-an-array-in-es6
// more consise
arr.slice(-1)[0]
// or more faster, according to https://jsperf.com/slice-vs-length-1-arr
arr[arr.length -1]
What does void 0
mean? (1091 votes)
https://stackoverflow.com/questions/7452341/what-does-void-0-mean https://stackoverflow.com/questions/1291942/what-does-javascriptvoid0-mean