Detailed Object.keys method of Object.keys

Detailed methods of Object.keys

 

First, grammar

Object.keys(obj)

Parameters: enum to return to their own property objects

Return Value: a string array given object attributes represent all enumerable

Second, processed, returns the attribute array enumerable

let person = {name:"张三",age:25,address:"深圳",getName:function(){}}

Object.keys(person) // ["name", "age", "address","getName"]

Third, the processing array, return the array index value

let arr = [1,2,3,4,5,6]

Object.keys(arr) // ["0", "1", "2", "3", "4", "5"]

Fourth, the character string processing , returns the array index value

let str = "saasd string"

Object.keys(str) // ["0", "1", "2", "3", "4", "5", "6", "7"]

V. General Tips

let person = {name:"张三",age:25,address:"深圳",getName:function(){}}

Object.keys(person).map((key)=>{

  person [key] // Get the value corresponding to the attribute, do some processing

}) 

Six, Object.values ​​() and Object.keys () is the reverse operation, the value of an object is converted to an array

 

 

First, grammar

Object.keys(obj)

Parameters: enum to return to their own property objects

Return Value: a string array given object attributes represent all enumerable

Second, processed, returns the attribute array enumerable

let person = {name:"张三",age:25,address:"深圳",getName:function(){}}

Object.keys(person) // ["name", "age", "address","getName"]

Third, the processing array, return the array index value

let arr = [1,2,3,4,5,6]

Object.keys(arr) // ["0", "1", "2", "3", "4", "5"]

Fourth, the character string processing , returns the array index value

let str = "saasd string"

Object.keys(str) // ["0", "1", "2", "3", "4", "5", "6", "7"]

V. General Tips

let person = {name:"张三",age:25,address:"深圳",getName:function(){}}

Object.keys(person).map((key)=>{

  person [key] // Get the value corresponding to the attribute, do some processing

}) 

Six, Object.values ​​() and Object.keys () is the reverse operation, the value of an object is converted to an array

 

 

Guess you like

Origin www.cnblogs.com/fqh123/p/12111311.html