Skip to content

Instantly share code, notes, and snippets.

@Alger23
Created August 28, 2017 09:27
Show Gist options
  • Select an option

  • Save Alger23/cea5dbbd4b95af9f2f39d7e45f648a68 to your computer and use it in GitHub Desktop.

Select an option

Save Alger23/cea5dbbd4b95af9f2f39d7e45f648a68 to your computer and use it in GitHub Desktop.
FindIndex.js
var elementPos = array.map(function(x) {return x.id; }).indexOf(idYourAreLookingFor);
var objectFound = array[elementPos];
ES5 syntax: [{id:1},{id:2},{id:3},{id:4}].findIndex(function(obj){return obj.id == 3})
ES6 syntax: [{id:1},{id:2},{id:3},{id:4}].findIndex(obj => obj.id == 3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment