image.png

image.png

image.png

image.png

image.png

Objects - Data Structures in JS


https://app.eraser.io/workspace/3gdsQ3KkAON32PoR5Hsb

JavaScript Array Methods Cheat Sheet with Problems & Use Cases

Method Use Case 📌 Example Problem 🤔
map() When you need to transform each element in an array and create a new array. Given an array of prices [100, 200, 300], increase each by 10%.
filter() When you need to extract specific elements based on a condition. From [10, 15, 20, 25], return only even numbers.
reduce() When you need to combine all elements into a single value (sum, product, etc.). Calculate the sum of [1, 2, 3, 4].
forEach() When you need to iterate over an array without creating a new one. Given an array of strings, print each one to the console.
find() When you need to find the first element that satisfies a condition. Find the first number greater than 10 in [5, 12, 8, 130].
some() When you need to check if at least one element meets a condition. Check if any number in [3, 5, 8] is greater than 6.
every() When you need to check if all elements satisfy a condition. Check if all numbers in [2, 4, 6] are even.
includes() When you need to check if a specific value exists in an array. Check if "banana" exists in ['apple', 'banana', 'mango'].
sort() When you need to sort elements in ascending or descending order. Sort [4, 2, 8, 1] in ascending order.
slice() When you need to extract a portion of an array without modifying the original. Extract [2, 3, 4] from [1, 2, 3, 4, 5].