Skip to content

Instantly share code, notes, and snippets.

@syul
Created December 7, 2016 07:12
Show Gist options
  • Save syul/eb3911bc53336d251bd561b6560da6e9 to your computer and use it in GitHub Desktop.
Save syul/eb3911bc53336d251bd561b6560da6e9 to your computer and use it in GitHub Desktop.
find the index of the element in array
var a = ['one', 'two', 'three'];
//what is the index of the element 'two'
var index = a
.map(function (el, index) {
return {
index: index,
value: el
};
})
.filter(function (el) {
return el.value === 'two';
})
.map(function (el) {
return el.index
})[0];
console.log(index)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment