Object Method
Last updated
Last updated
v
Object.hasOwn(obj, key)
ๅไปฃ่็ Object.hasOwnProperty
let b = ["a", "b", ,"d"] for (let i = 0; i< b.length; i++){
if (Object.hasOwn(b, i)) {
console.log(b[i])
}
}; // 'a'. 'b' 'd'
Object.prototype.toString.call()
ๅคๆทๆฏๅช็จฎๅๅฅๅฅฝ็จ
Object.keys(obj)
Array ไนๆฏ Object ไธ็จฎๆไปฅไนๅฏไปฅ
Object.keys({a: 1, b: 2}) // [a, b] Object.keys(["a", "b"]) // [0, 1]
Object.values(obj)
Object.values({a: 1, b: 2}) // [1, 2] Object.values(["a", "b"]) // [1, 2]
Object.entries(obj)
Object.entries({a: 1, b: 2}) // [[a, 1], [b,2]] Object.entries(["a", "b"]) // [[0,a], [1,b]]
Object.fromEntries(arr)
่ท Object.entries(obj) ็ธๅ
Object.fromEntries([[0,'a'], [1,'b']]) // [{0: 'a', 1: 'b'}