JavaScript array methods 🚀🔥
1. Adding & Removing Elements
push(item) → Adds an item at the end of the array.
pop() → Removes the last item from the array.
unshift(item) → Adds an item at the beginning of the array.
shift() → Removes the first item from the array.
-----------------------------------------------------
2. Searching in an Array
indexOf(item) → Returns the index of the first occurrence of an item (or -1 if not found).
lastIndexOf(item) → Returns the index of the last occurrence of an item.
includes(item) → Returns true if the item exists in the array, otherwise false.
find(callback) → Returns the first matching element based on a condition.
findIndex(callback) → Returns the index of the first matching element based on a condition.
-----------------------------------------------------
3. Modifying or Transforming Arrays
map(callback) → Creates a new array by modifying each item.
filter(callback) → Creates a new array with only the items that match a condition.
reduce(callback, initialValue) → Reduces the array to a single value (e.g., sum of all numbers).
forEach(callback) → Runs a function for each item (but doesn’t create a new array).
some(callback) → Returns true if at least one item matches a condition.
every(callback) → Returns true if all items match a condition.
-----------------------------------------------------
4. Sorting & Reversing
sort(compareFunction) → Sorts the array (default is ascending, but can be customized).
reverse() → Reverses the order of the elements in the array.
-----------------------------------------------------
5. Extracting & Combining Arrays
slice(start, end) → Extracts a portion of an array (without modifying the original).
splice(start, deleteCount, item1, item2, …) → Changes the array by adding/removing elements.
concat(array2, array3, …) → Joins two or more arrays into a new array.
flat(depth) → Flattens nested arrays into a single array (default depth is 1).
join(separator) → Converts an array to a string, with elements separated by a given character.
-----------------------------------------------------
6. Converting & Checking Arrays
toString() → Converts an array to a string.
Array.isArray(value) → Checks if a value is an array (true or false).
#JavaScript #JSDeveloper #LearnJavaScript #JavaScriptTutorial #Coding #JavaScriptArrays
#ArrayMethods #JSArrayTips #CodingWithJS #JavaScriptTricks #WebDevelopment #coder
#CodeNewbie #FrontendDeveloper #coding #ProgrammingTips #100DaysOfCode #react