📜  javascript 反射 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:40.748000             🧑  作者: Mango

代码示例1
let kossher = [ {player1:"kir"},{player2:"kos"},{player3:"kir"} ]

let tirisaam = {}

kossher.forEach((obj)=>{
    Object.getOwnPropertyNames(obj).forEach((propertyName)=>{  // getOwnPropertyNames : returns list of property names and i did a foreach on it.
        tirisaam[propertyName] = obj[propertyName]
    })
})

console.log(tirisaam) //Object { player1: "kir", player2: "kos", player3: "kir" }