هیچ دوره ای در سبد آموزش شما وجود ندارد
حلقه ی For/In در جاوا اسکریپت
صفحه نخست »
javascript »
مبانی جاوا اسکریپت »
به تعداد دفعات معین خاصیت های (property) یک شی را تکرار می کند، برای حرکت درون اعضای يک آرايه يا مجموعه property های يک شی استفاده می شود. به ازای خواندن هر يک از اعضا آرايه يا يکی از property های شی مورد نظر، يکبار statement داخل حلقه اجرا خواهد شد.
سینتکس:
for (variablename in object) { statement or block to execute }
مثال:
<html> <body> <script type = "text/javascript"> <!-- var aProperty; document.write("Navigator Object Properties<br /> "); for (aProperty in navigator) { document.write(aProperty); document.write("<br />"); } document.write ("Exiting from the loop!"); //--> </script> <p>Set the variable to different object and then try...</p> </body> </html>
خروجی:
Navigator Object Properties serviceWorker webkitPersistentStorage webkitTemporaryStorage geolocation doNotTrack onLine languages language userAgent product platform appVersion appName appCodeName hardwareConcurrency maxTouchPoints vendorSub vendor productSub cookieEnabled mimeTypes plugins javaEnabled getStorageUpdates getGamepads webkitGetUserMedia vibrate getBattery sendBeacon registerProtocolHandler unregisterProtocolHandler Exiting from the loop! Set the variable to different object and then try...