JavaScript Functions

String Functions

  • length: Returns the number of characters in a string.

  • charAt(index): Returns a string containing the character at the specified index.

  • concat(string): Returns a new string that concatenates the string on which the method is called and the string provided as an argument.

  • indexOf(term, start): This method returns the first index at which term appears in the string or -1 if there is no match. The optional start argument specifies the start index for the search.

  • replace(term, newTerm): This method returns a new string in which all instances of term are replaced with newTerm.

  • slice(start, end): Returns a substring containing the characters between the start and end indices.

  • split(term): This method splits up a string into an array of values that were separated by term.

  • toUpperCase(): Returns a new string with all characters in upper case.

  • toLowerCase(): Returns a new string with all characters in lower case.

  • trim(): This method returns a new string from which all the leading and trailing white space characters have been removed.

Array Functions

  • concat(otherArray): This method returns a new array that concatenates the array on which it has been called with the array specified as the argument. Multiple arrays can be specified.

  • join(separator): This method joins all the elements in the array to form a string. The argument specifies the character used to delimit the items.

  • pop(): This method removes and returns the last item in the array.

  • shift(): This method removes and returns the first item in the array.

  • push(item): This method appends the specified item to the end of the array.

  • unshift(item): This method inserts a new item at the start of the array.

  • reverse(): This method returns a new array that contains the items in reverse order.

  • slice(start, end): This method returns a section of the array.

  • sort(): This method sorts the array. An optional comparison function can be used to perform custom comparisons.

  • splice(index, count): This method removes count items from the array, starting at the specified index. The removed items are returned as the result of the method.

  • every(test): This method calls the test function for each item in the array and returns true if the function returns true for all of them and false otherwise.

  • some(test): This method returns true if calling the test function for each item in the array returns true at least once.

  • filter(test): This method returns a new array containing the items for which the test function returns true.

  • find(test): This method returns the first item in the array for which the test function returns true.

  • findIndex(test): This method returns the index of the first item in the array for which the test function returns true.

  • foreach(callback): This method invokes the callback function for each item in the array, as described in the previous section.

  • includes(value): This method returns true if the array contains the specified value.

  • map(callback): This method returns a new array containing the result of invoking the callback function for every item in the array.

  • reduce(callback): This method returns the accumulated value produced by invoking the callback function for every item in the array.