如何提取数组里的某个属性
1、一、indexOf()方法
// indexOf 返回数组中元素的下标,若没找到则返回-1

2、var arr = ['lily','Anna','John','Trist','Hana'];
var index = arr.indexOf(3); //返回 John
3、二、filter()方法
var arr = [
{name:"桌子",money:220},
{name:"板凳",money:60},
{name:"床",money:1256}
]
var filterArr = arr.filter(function(elem,index,arr){
return elem.money>=200
})
//[{name:"桌子",money:220},{name:"床",money:1256}]

4、filter() 方法将匹配元素集合缩减为匹配指定选择器的元素.该方法不改变原数组,返回的是筛选后满足条件的数组.

5、拓展:ES6从数组和对象中获取数据的方法

6、const names = ['Luke', 'Eva', 'Phil']
// 提取数组中第一个元素
const [first] = names;
console.log(first); // 'Luke'
// 提取数组中第一个和第二个元素
const [first, second] = names;
console.log(first, second); // 'Luke' 'Eva'

7、const person = {
name: 'Luke',
age: '24',
facts: {
hobby: 'Photo',
work: 'Software Developer'
}
}
// 从 person 中提取 name 和 age
const {name, age} = person;
console.log(name, age); // 'Luke' '24'
// 提取嵌套值 person 中的 hobby
const {facts: {hobby}} = person;
console.log(hobby); // 'Photo'
