# 章序号/节序号/节/笔记序号
codecademy, Iterators
# 概念阐释
## 语义
`findIndex()`方法返回数组中满足条件的第一个元素的**索引**。若没有找到对应元素则返回 -1。
## 语法
```
// 箭头函数
findIndex((element) => { /* … */ } )
//内联回调函数
findIndex(function(element) { /* … */ })
```
# 举例子
```js
const jumbledNums = [123, 25, 78, 5, 9];
const lessThanTen = jumbledNums.findIndex(num => {
return num < 10;
});
console.log(lessThanTen); // 小于10的第一个元素的索引位置是 Output: 3
```
# 类比、比较与对比
# 问题
参考概念卡片的写法
1. 用 `.findIndex()` 找到 `'elephant'` 的位置, 使用变量名`const` variable named `foundAnimal`. 🌟
```js
const animals = [
"hippo",
"tiger",
"lion",
"seal",
"cheetah",
"monkey",
"salamander",
"elephant",
];
```
1. 用 `.findIndex()` 找到's'开头的单词,创建变脸名`startsWithS`.🌟
2. print 所有s开头的单词应该用哪个Array方法?
# 问题答案
```js
const foundAnimal = animals.findIndex((animal) => {
return animal === "elephant";
});
console.log(foundAnimal);
const startsWithS = animals.findIndex((element) => {
return element[0] === 's';
});
//另一种写法
const startWith = animals.findIndex(
element => {
return element.startsWith('s');
}
);
console.log(startsWithS);
//filter()
```
# 备注(经验集/错误集)
## 经验集
## 错误集
## 参考资料