Object, Array, String: Methods
Object methods
- delete()
-
- removes the property of an object
- returns bolean
- assign()
-
- makes copy of values from one or more source objects to a target object
- returns target object
Array methods
Array: search, select
- filter()
-
- finds all elements matching query; query can be a function returning bolean
- makes new array from the result of callback function, if negative new array
is empty; does not change the original array
- map()
-
- calls a function for all elements of an array
- makes new array from the result of callback function; does not change the original array
- includes()
-
- finds if searched element is in an array
- returns bolean
- find()
-
- finds the first element matching query
- returns it or undefined if not found
- findIndex()
-
- finds the first element matching query
- returns its index or -1 if not found
- indexOf()
-
- finds if searched element is in an array
- returns its index or -1 if not found
- lastIndexOf()
-
- the same as indexOf but starts from the end
- some()
-
- find if any element matches request
- returns bolean
- every()
-
- find if every elements match request
- returns bolean
Array: change
- join()
-
- joins the elements of an array into a string; argument is a separator
- returns string
- reduce()
-
- reduces values of all array elements to a single value kept in accumulator
- reducer function
- reduceRight()
-
- the same as reduce() but starts from the end
- reverse()
-
- reverses the order of all elements of an array
- sort()
-
- sorts the elements of an array
- changes the original array
Array: add, remove
- shift()
-
- removes the first element of an array
- returns it
- pop()
-
- removes the last element of an array
- returns it
- unshift()
-
- adds a new element at the beginning
- returns lenght of an array
- push()
-
- adds a new element at the end of an array
- returns lenght of an array
- slice()
-
- selects a part of an array specified by beginning and end of splice or all array if end is not specified
- returns the new array
- does not change the original array; both parameters are optional: start (from where to select), and end
(index where to stop; index element is not taken), defaults are zero and the end
- splice()
-
- adds/removes elements from an array specified by beginning and end of splice, if beginning is negative it
operates at the end of an array; end is specified by number of elements to delete, if 0 it just place new
element into an array
- returns removed elements
- changes the original array; index (from what point to change) is obligatory, end (how many elements to
delete) and elements are optional
String methods
- charAt()
-
- finds the character at the specified index (starts with 0, -1 is the last one) in a string
- returns it
- concat()
-
- joins two or more strings, those after first are passed as an arguments; does ot change them
- returns new concatenated string
- includes()
-
- checks if the calling string contains a string passed as an argument; case sensitive
- returns bolean
- endsWith()
-
- checks if the calling string ends with a string passed as an argument; case sensitive
- returns bolean
- indexOf()
-
- finds first ocurence of a specified argument; optional second argument is an integer specifying index of
place where to start searching; case sensitive
- returns index, or -1 if not found
- lastIndexOf()
-
- the same as indexOf(), but backwards
- match()
-
- searches a string for a match against a regular expression; without g modifier (global) it finds only the
first one
- returns the matches (as substring), index, and the input, all as an Array object, or null if not found
- repeat()
-
- finds an element at index given as an argument
- returns a string of that element repeated number of times (this number is a second argument), or empty
string if no argument or argument 0
- replace()
-
- finds a match between a regular expression (or a specified value) and a string; does not change the
original string; without g modifier (global) it replaces only the first occurence
- returns a new string where the specified values are replaced, or the original string if no match is found
.
- search()
-
- searches for a match between a string or regular expression and a specified string
- returns the index of the first character of the first match, or -1 if no match is found
- slice()
-
- extracts a section of a string, from the index specified in the first argument, to index specified by the
second argument (i, j-1), or end of string if there's no second argument; negative numbers are extracting
from the end
- returns result, or the entire string if no arguments are passed, as a new string
- split()
-
- splits a string into an array of strings by separating the string into substrings, argument is the
separator; does not change the original string
- returns an array of substrings, or the entire array of string's elements if no argument or empty argument
('') are passed
- startsWith()
-
- checks if a string begins with a string passed as an argument; case sensitive
- returns bolean
- substr()
-
- extracts strings of number of characters specified in the second argument from index specified in the
first argument; negative number extracts from the end of a string; does not change the original string
- returns a substring of elements at a given range
- substring()
-
- extracts strings form index specified in the first argument to index specified in the second argument;
does not change the original string
- returns a substring of elements at a given range
- toLowerCase()
-
- does not change the original string
- returns the calling string converted to lowercase letters
- toUpperCase()
-
- does not change the original string
- returns the calling string converted to uppercase letters
- trim()
-
- removing whitespaces from both ends of string; does not change the original string
- returns changed string
- trimLeft()
-
- removing whitespace from the left side
- returns changed string
- trimRight()
-
- removing whitespace from the right side
- returns changed string
back to the top of page