Object get keys and values method


Posted by Jim on 2022-09-16

Object.keys(object)

  • 回傳 object 裡所有 key 的 array
cont test = {a: 1, b: 2, c: 3};
console.log(Object.keys(test))
//output: [a, b, c]

Object.values(object)

  • 回傳 object 裡所有 value 的 array
cont test = {a: 1, b: 2, c: 3};
console.log(Object.values(test))
//output: [1, 2, 3]

Object.entries(object)

  • 回傳 object 裡所有 [key, value] 的 array
cont test = {a: 1, b: 2, c: 3};
console.log(Object.entires(test))
//output: [[a, 1], [b, 2], [c, 3]]

#javascript #object #Array







Related Posts

JS踩坑筆記 -  function 宣告

JS踩坑筆記 - function 宣告

JavaScript 程式執行原理:Scope Chain 與 var, let, const

JavaScript 程式執行原理:Scope Chain 與 var, let, const

Day06: GraphQL - Enumeration and list types wiht node.js

Day06: GraphQL - Enumeration and list types wiht node.js


Comments