Author: zeel
Message:
All the Array.prototype
built-in loops are so useful.
Array.prototype.every() // Returns true if all elements pass a test
Array.prototype.filter() // Create and return a new array of elements that pass a test
Array.prototype.find() // Return the first element to pass a test
Array.prototype.forEach() // Apply a function to each element in order
Array.prototype.reduce() // Accumulate a value based on all elements
Array.prototype.reduceRight() // As above in reverse order
Array.prototype.some() // Returns true if any element passes a test
// Not really like the others, but special mention:
Array.prototype.sort() // Sorts the array based on a custom compare function
And combining those with Object.values()
or Object.entries()
makes life so much easier.
Object.entries(object).find(([key, value]) => /* test */)