JS Other Array Methods Flashcards
Concat
.concat(condition);
Concatenates two arrays into one array
The Concat method returns (shows) the value of two arrays concatenated into a single array
IndexOf
.indexOf(condition);
Returns the array (Or string) index position of the value entered
Includes
.includes(condition);
Determines if an array includes a specific value. Returns a boolean value (AKA True or False)
Reverse
arrayName.reverse();
Reverses the order of the items in the array.
// NOTE: Returns (shows) the array with the items in reverse order. Also, the Reverse method alters the value of the array it is used on.
Slice
stringOrArrayName.slice(#, #);
Returns a specified section of a String or an Array. First number determines the starting index. Second number determine the stopping index. Stops before the second number/index (AKA Does NOT include second index).
// NOTE: If a second number is NOT included, then Slice will return (show) the item at the starting index as well as all items that follow.
Splice
Syntax Example for Splice:
array.splice(Starting Index, Number of Indexes to Remove, Added Item Value(s))
Removes, Replaces, or Adds item(s) to an array. // First position determines the starting index. Second position determines how many array items to remove starting at the starting index. Third position and on are optional positions that determines the value(s) being set for that/those position(s).
Removing with Splice
arrayName.splice(#, #);
NOTE: The array item(s) removed are returned which can be set to a variable
Replacing with Splice
arrayName.splice(#, #, “replacingItem”, “newItem1”);
NOTE: New value is added at the index specified for the starting index
Adding with Splice
arrayName.splice(#, #, “newItem”)
NOTE: If there is an item at the specified starting index, then it will be shifted to the right (AKA To the next index)