🧑💻 JavaScript Challenge of the Day! 🧑💻
Today’s focus: Array Methods in JavaScript 🚀 Arrays are powerful in JS, and learning how to use methods like .map(), .filter(), and .reduce() can make your code so much cleaner and efficient! Here's a quick rundown:
const numbers = [1, 2, 3, 4, 5];
// .map() - creates a new array with each element doubled
const doubled = numbers.map(num => num * 2); // [2, 4, 6, 8, 10]
// .filter() - creates a new array with only even numbers
const evens = numbers.filter(num => num % 2 === 0); // [2, 4]
// .reduce() - sums all the elements
const sum = numbers.reduce((acc, num) => acc + num, 0); // 15
These methods are lifesavers when working with data! Give them a try, and let me know how you use them in your projects! 💡 #DevJourney
Today’s focus: Array Methods in JavaScript 🚀 Arrays are powerful in JS, and learning how to use methods like .map(), .filter(), and .reduce() can make your code so much cleaner and efficient! Here's a quick rundown:
const numbers = [1, 2, 3, 4, 5];
// .map() - creates a new array with each element doubled
const doubled = numbers.map(num => num * 2); // [2, 4, 6, 8, 10]
// .filter() - creates a new array with only even numbers
const evens = numbers.filter(num => num % 2 === 0); // [2, 4]
// .reduce() - sums all the elements
const sum = numbers.reduce((acc, num) => acc + num, 0); // 15
These methods are lifesavers when working with data! Give them a try, and let me know how you use them in your projects! 💡 #DevJourney