function Antzone(){ this.webName="螞蟻部落"; this.age=6; } Antzone.prototype={ address:"青島市南區" }
var auth = { ADD:false, LIST:false, EXPORT:false, IMPORT:false, SEARCH:false }; console.log(Object.keys(auth));
var auth1 = ["ADD","LIST","SEARCH"]; let antzone=new Antzone(); console.log(Object.getOwnPropertyNames(antzone));
var names = Object.getOwnPropertyNames(auth); console.log(names);
if(auth1.length > 0){ for(var i=0;i<names.length;i++){ for(var j=0;j<auth1.length;j++){ if(auth1[j] == names[i]){ auth[names[i]]=true; break; } } } } console.log(auth);
結果:
js output console.log: ["ADD", "LIST", "EXPORT", "IMPORT", "SEARCH"] console.log: ["webName", "age"] console.log: ["ADD", "LIST", "EXPORT", "IMPORT", "SEARCH"] console.log: { ADD: true LIST: true EXPORT: false IMPORT: false SEARCH: true }
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/179494.html
標籤:JavaScript
上一篇:React實作頂部固定滑動式導航欄(導航條下拉一定像素時顯示原導航欄樣式)
下一篇:vue實作組件切換的兩種方式
