前端笔试练习一
前端筆試練習一
請編寫一段程序,將一個對象和它直接、間接引用的所有對象的屬性字符串放入一個數(shù)組。如var o = {a:1,{b:2,c:{d:1}}}這里o經(jīng)過處理后,應(yīng)該得到["a","b","c","d"]
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <script type="text/javascript"> 5 window.onload = function(){ 6 7 //請編寫一段程序,將一個對象和它直接、間接引用的所有對象的屬性字符串放入一個數(shù)組。如 8 9 //var o = {a:1,{b:2,c:{d:1}}}這里o經(jīng)過處理后,應(yīng)該得到["a","b","c","d"] 10 11 12 var o = {a:1,b:{c:{d:1}}};//輸出 a b c d 13 //var o = {a:1,b:{c:2}}; 14 alert(getProperties(o)); 15 } 16 function getProperties(obj){ 17 var property = []; 18 for(var key in obj){ 19 property.push(key); 20 } 21 for(var key in obj){ 22 if(typeof obj[key] == 'object'){ 23 return property.concat(arguments.callee(obj[key])); 24 } 25 } 26 return property; 27 } 28 </script> 29 </head> 30 31 <body> 32 33 </body> 34 </html>
?
轉(zhuǎn)載于:https://www.cnblogs.com/allenxing/p/3311142.html
總結(jié)
- 上一篇: 开发 Windows 8 Bing地图应
- 下一篇: ftp简介