Created
December 7, 2016 07:12
-
-
Save syul/eb3911bc53336d251bd561b6560da6e9 to your computer and use it in GitHub Desktop.
find the index of the element in array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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