js中用for循環獲取對象的變量


var person={
name:"ai",
age:"22"
};

for (var n in person){
console.log(n);
console.log(typeof n);
console.log(person.n);//常會思路是錯的,這樣他會找person.n即n這個屬性,person中並不存在
console.log(person[n]);//上面那樣是找常量,用中括號會找變量
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM