Skip to content

Instantly share code, notes, and snippets.

@VPAbraham
Created August 29, 2019 17:35
Show Gist options
  • Select an option

  • Save VPAbraham/bdef78260b453133a15bd398ab3450a2 to your computer and use it in GitHub Desktop.

Select an option

Save VPAbraham/bdef78260b453133a15bd398ab3450a2 to your computer and use it in GitHub Desktop.
Iterator Methods Cheat Sheet

Iterator Methods Cheat Sheet

Contents:


concat()

  • The concat() method is used to join two or more arrays.

  • This method does not change the existing arrays, but returns a new array, containing the values of the joined arrays.

Ex:

var hege = ["Cecilie", "Lone"];
var stale = ["Emil", "Tobias", "Linus"];
var kai = ["Robin"];
var children = hege.concat(stale, kai);
//children === [Cecilie, Lone, Emil, Tobias, Linus, Robin]

filter()

  • The filter() method creates an array filled with all array elements that pass a test (provided as a function).

  • syntax: array.filter(function(currentValue, index, arr), thisValue)

Example 1

var words = ['spray', 'limit', 'elite', 'exuberant', 'destruction']

const result = words.filter(word => word.length > 6);

//output: ['exuberant', 'destruction', 'present']

Example 2

var fruits = ['apple', 'banana', 'grapes', 'mango', 'orange'];

function filterItems(arr, query) {
  return arr.filter(element => {
    return element.toLowerCase().indexOf(query.toLowerCase())
  });
}

console.log(filterItems(fruits, 'ap')); // ['apple', 'grapes']
console.log(filterItems(fruits, 'an')); // ['banana', 'mango', 'orange']

find()


findIndex()


forEach()


includes()


indexOf()


join()


keys()


map()


pop()


push()


reduce()


reverse()


shift()


slice()


sort()


splice()


toString()


unshift()


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment