1、語法html
Object.keys(obj)數組
參數:要返回其枚舉自身屬性的對象htm
返回值:一個表示給定對象的全部可枚舉屬性的字符串數組對象
2、處理對象,返回可枚舉的屬性數組blog
let person = {name:"張三",age:25,address:"深圳",getName:function(){}}索引
Object.keys(person) // ["name", "age", "address","getName"]字符串
3、處理數組,返回索引值數組get
let arr = [1,2,3,4,5,6]io
Object.keys(arr) // ["0", "1", "2", "3", "4", "5"]function
4、處理字符串,返回索引值數組
let str = "saasd字符串"
Object.keys(str) // ["0", "1", "2", "3", "4", "5", "6", "7"]
5、經常使用技巧
let person = {name:"張三",age:25,address:"深圳",getName:function(){}}
Object.keys(person).map((key)=>{
person[key] // 獲取到屬性對應的值,作一些處理
})
6、Object.values()和Object.keys()是相反的操做,把一個對象的值轉換爲數組