Skip to content

Instantly share code, notes, and snippets.

@MicFin
Created May 8, 2017 18:48
Show Gist options
  • Save MicFin/6417ae43e20abd587d0924349a37385f to your computer and use it in GitHub Desktop.
Save MicFin/6417ae43e20abd587d0924349a37385f to your computer and use it in GitHub Desktop.
'use strict'
// Starting array
const ages = [7, 24, 21, 18, 22]
// Use indexOf to find the position of 21
ages.indexOf(21) // 2
// Use findIndex to find the position of first age over 21
// using a predicate function
const isAdult = (age) => {
return age >= 21
}
ages.findIndex(isAdult) // 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment