10 JavaScript Array methods to simplify your code.
🧵
1. filter()
The `filter()` method creates a new array with all elements that pass the test implemented by the provided function.
2. forEach()
The `forEach()` method executes a provided function once for each array element.
3. some()
The `some()` method tests whether at least one element in the array passes the test implemented by the provided function. It returns a Boolean value.
4. every()
The `every()` method tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.
5. includes()
The `includes()` method determines whether an array includes a certain value among its entries, returning true or false as appropriate.
6. map()
The `map()` method creates a new array populated with the results of calling a provided function on every element in the calling array.
7. reduce()
The `reduce()` method executes a reducer function (that you provide) on each element of the array, resulting in a single output value.
8. sort()
The `sort()` method sorts the elements of an array in place and returns the sorted array. The default sort order is ascending, built upon converting the elements into strings, then comparing their sequences of UTF-16 code units values.
9. find()
The `find()` method returns the value of the first element in the provided array that satisfies the provided testing function.
10. findIndex()
The `findIndex()` method returns the index of the first element in the array that satisfies the provided testing function. Otherwise, it returns -1, indicating that no element passed the test.
Did you find this useful?
Retweet the 1st tweet and help others discover it.
Happy coding!
You can bookmark this thread as a post if you want.
There are 26 modules to explore, all created by Google trainers, and packed with practical exercises and real-world examples to help you turn knowledge into action.
Using `console.log()` for JavaScript debugging is the most common practice. But, there is more…
🧵
1/ The most common Console methods:
console.log() – For general output of logging information.
console. info() – Informative logging.
console.debug() – A message to the console with the log level debug.
console.warn() – A warning message.
console.error() – An error message.
2/ Custom CSS styles for a console.log():
The `console.log` output can be styled in DevTools using the CSS format specifier.
1/ Create a beautiful text portrait with a few lines of CSS:
2/ When you work with transparent images you can use the `drop-shadow()` filter function to create a shadow on the image's content, instead of `box-shadow` property which creates a rectangular shadow behind an element's entire box: