1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <meta name="viewport" content="width=device-width"> 6 <title>列出所有的属性键</title> 7 </head> 8 <body> 9 10 </body> 11 </html>
1 function getAllpropertyNames(obj){ 2 var result=[]; 3 while(obj){ 4 Array.prototype.push.apply(result,Object.getOwnPropertyNames(obj)); 5 // obj = Object.getPrototypeOf(obj); 6 } 7 return result; 8 } 9 10 var all = getAllpropertyNames(Array); 11 12 console.log(all);