HomeGorakh Raj Joshi

Array/String Methods

These methods cover a wide range of operations you can perform on arrays and strings

  • #Extra

Array Methods

  • map: Executes a provided function once for each array element and creates a new array with the results.
  • filter: Creates a new array containing elements that pass the specified condition.
  • reduce: Reduces the array to a single value by applying a function to each element.
  • reduceRight: Similar to `reduce`, but processes the array from right to left.
  • push: Adds one or more elements to the end of an array and returns the new length.
  • pop: Removes the last element from an array and returns that element.
  • shift: Removes the first element from an array and returns that removed element.
  • unshift: Adds one or more elements to the beginning of an array and returns the new length.
  • splice: Adds or removes elements from an array at a specified index.
  • slice: Returns a shallow copy of a portion of an array as a new array.
  • concat: Joins two or more arrays and returns a new array.
  • some: Checks if at least one element in the array satisfies a provided condition.
  • every: Checks if all elements in the array satisfy a provided condition.
  • fill: Fills elements of an array with a static value from a start index to an end index.
  • reverse: Reverses the order of elements in an array.
  • includes: Checks if an array contains a specific element.
  • at: Returns the element at a specified index in the array.
  • find: Returns the value of the first element in the array that satisfies a provided condition.
  • forEach: Executes a provided function once for each array element.
  • flat: Creates a new array with all sub-array elements concatenated into it recursively up to a specified depth.
  • flatMap: Maps each element using a mapping function and flattens the result into a new array.
  • indexOf: Returns the first index at which a specified element can be found in the array.
  • findIndex: Returns the index of the first element in the array that satisfies a provided condition.
  • lastIndexOf: Returns the last index at which a specified element can be found in the array.
  • join: Joins all elements of an array into a string.
  • sort: Sorts the elements of an array in place.
  • toString: Returns a string representing the array and its elements.
  • from: Creates a new array from an array-like or iterable object.
  • entries: Returns a new array iterator object containing key/value pairs for each index in the array.
  • isArray: Checks if a value is an array.

https://medium.com/@silviyafrontenddev/30-javascript-array-methods-a-cheat-sheet-for-developers-98fc4dd33957

String Methods

  • length: Returns the number of characters in a string.
  • concat: Combines two or more strings and returns a new string.
  • substring: Extracts a portion of a string based on start and end indexes.
  • indexOf: Returns the index of the first occurrence of a specified substring within a string.
  • replace: Replaces specified substrings within a string with new values.
  • toUpperCase: Converts all characters in a string to uppercase.
  • toLowerCase: Converts all characters in a string to lowercase.
  • startsWith: Checks if a string starts with a specific substring.
  • endsWith: Checks if a string ends with a specific substring.
  • trim: Removes whitespace from the beginning and end of a string.
  • split: Divides a string into an array of substrings based on a specified separator.
  • charAt: Retrieves the character at a specific index within a string.
  • charCodeAt: Returns the Unicode value of a character at a specified index.
  • includes: Checks if a string contains a specific substring.
  • match: Determines if a string matches a particular pattern using regular expressions.
  • repeat: Repeats a string a specified number of times.
  • lastIndexOf: Finds the index of the last occurrence of a specified substring within a string.
  • slice: Extracts a portion of a string based on start and end indexes.
  • isEmpty: Checks if a string is empty.
  • isNaN: Determines if a string represents a valid number.

https://zuxcode.medium.com/20-javascript-string-methods-3ce70d1fb52

Gorakh Raj Joshi

Senior Fullstack Engineer: Specializing in System Design and Architecture, Accessibility, and Frontend Interface Design

LinkedIn

GitHub

Email

All rights reserved © Gorakh Raj Joshi 2024