Object.fromEntries

//數組轉換成對象
const arr = [['foo', 1],['bar', 2]]
const obj = Object.fromEntries(arr)
console.log(obj.bar)

//找出key的長度爲3的值
const obj = {
  abc: 1,
  def: 2,
  ghewe: 3
}

let res = Object.fromEntries(
  Object.entries(obj).filter(([key, val]) => key.length === 3)
)
console.log(res)
相關文章
相關標籤/搜索