我有一個對象,看起來像這樣:更換對象字段
PetForm
{
name:"Bobo",
type:"Golden Retriever",
food:null,
toys:null,
....
}
我想更換空的值的字段爲空字符串是這樣的:
結果:
{
name:"Bobo",
type:"Golden Retriever",
food:"",
toys:"",
....
}
我做了以下內容:
Object.keys(PetForm).forEach((key) => (PetForm[key] === null) && PetForm[key] == "");
我在這種方法中遺漏了什麼?
能否請您通過簡單的代碼片段闡述你的答案。這真的有幫助! – RBT