for-in 语句:
for-in 语句用于对数组或者对象的属性进行循环操作。
for-in 循环中的代码每执行一次,就会对数组的元素或者对象的属性进行一次操作。
语法:
for (变量 in 对象)
{
在此执行代码
}
例如:
JavaScript Code复制内容到剪贴板
for (var propName in window){
document.write(propName);
document.write("<br/>");
}
运行后,页面上会显示(BOM中window对象的所有属性,注意:通过for-in循环输出的属性名的顺序是不可预测的,因为ECMAscript对象的属性没有顺序):
window
top
location
__ActiveXObjectStub
external
v8Locale
document
propName
CustomEvent
HTMLFontElement
SVGFESpotLightElement
HTMLBaseFontElement
Uint32Array
Entity
StyleSheetList
StorageEvent
applicationCache
OverflowEvent
CanvasGradient
screenY
webkitIDBObjectStore
HTMLSpanElement
SVGTSpanElement
SVGFEMergeElement
PageTransitionEvent
innerWidth
HTMLTableSectionElement
webkitIDBIndex
personalbar
SVGAnimatedEnumeration
WebKitCSSKeyframeRule
webkitStorageInfo
SVGAltGlyphElement
SVGFEFuncAElement
SVGFEDistantLightElement
SVGFETurbulenceElement
webkitIDBDatabaseException
HTMLKeygenElement
SVGAltGlyphDefElement
SVGFEFuncBElement
WebGLProgram
FileError
SVGCursorElement
SVGAnimatedString
Node
Comment
HTMLOptionElement
WebGLRenderbuffer
HTMLAllCollection
NodeList
menubar
SVGAngle
SVGDefsElement
webkitIDBKeyRange
scrollX
frames
SVGFEDropShadowElement
webkitIndexedDB
Int16Array
localStorage
WebGLTexture
HTMLInputElement
Int8Array
SVGRectElement
SVGFETileElement
parent
HTMLTableRowElement
WebKitAnimationEvent
HTMLMediaElement
MessageEvent
MediaController
SVGPathSegCurvetoCubicSmoothRel
HTMLLIElement
StyleSheet
SVGElement
SVGFEColorMatrixElement
HTMLDivElement
WebGLActiveInfo
status
webkitIDBTransaction
WebGLBuffer
SharedWorker
SVGHKernElement
Notation
Attr
ProcessingInstruction
SVGImageElement
frameElement
SVGPathElement
SVGPolylineElement
webkitIDBDatabase
Blob
FileList
performance
SVGSwitchElement
HTMLModElement
CDATASection
CSSRuleList
FormData
DeviceOrientationEvent
SVGAnimatedAngle
SVGPatternElement
Range
NamedNodeMap
HTMLTableElement
navigator
SVGMetadataElement
Text
SVGPathSegLinetoAbs
SVGPathSegLinetoVerticalRel
DocumentFragment
CSSFontFaceRule
WebSocket
TextTrackList
HTMLMapElement
SVGNumberList
SVGFEMergeNodeElement
locationbar
HTMLAnchorElement
TouchEvent
CanvasRenderingContext2D
SVGZoomEvent
SVGFontElement
DOMException
scrollbars
HTMLScriptElement
HTMLTableCellElement
WebKitPoint
SVGLineElement
HTMLDListElement
scrollY
SVGSetElement
SVGPathSegCurvetoCubicAbs
HashChangeEvent
event
SVGAnimateTransformElement
TextTrackCue
screenX
SVGColor
SVGRadialGradientElement
SVGFEDiffuseLightingElement
crypto
webkitIDBCursor
HTMLLegendElement
SVGLinearGradientElement
HTMLUnknownElement
HTMLCollection
HTMLHeadingElement
HTMLParagraphElement
MessagePort
SVGFEMorphologyElement
SVGPointList
TextTrack
SVGFEConvolveMatrixElement
SVGFontFaceFormatElement
SVGForeignObjectElement
HTMLImageElement
HTMLVideoElement
SVGFEOffsetElement
webkitAudioPannerNode
pageXOffset
pageYOffset
SVGTRefElement
SVGFEBlendElement
SVGFilterElement
SVGRenderingIntent
WebKitTransitionEvent
CSSStyleSheet
HTMLBaseElement
SVGNumber
SVGAnimatedRect
SVGTextContentElement
MediaList
SVGAnimateMotionElement
SVGAnimatedNumber
SVGPoint
webkitPeerConnection
MimeType
SVGFECompositeElement
SVGUseElement
SVGPathSegCurvetoQuadraticAbs
SVGElementInstanceList
SVGTitleElement
DOMSettableTokenList
webkitIDBRequest
SVGFEFuncGElement
HTMLObjectElement
WheelEvent
statusbar
outerHeight
HTMLFrameElement
HTMLTableCaptionElement
CSSStyleRule
SVGAnimatedPreserveAspectRatio
CSSImportRule
webkitNotifications
defaultStatus
screen
CompositionEvent
Uint16Array
SVGAnimatedNumberList
ImageData
SVGAElement
SVGTextElement
SVGViewElement
XMLHttpRequest
SVGFEFloodElement
File
HTMLUListElement
HTMLMetaElement
DOMParser
DOMTokenList
SVGFontFaceElement
HTMLFrameSetElement
MediaError
EventSource
SVGDocument
SQLException
DOMStringList
ClientRect
SVGFEGaussianBlurElement
devicePixelRatio
screenLeft
Float32Array
SVGUnitTypes
SVGAnimatedBoolean
HTMLIFrameElement
CSSPageRule
clientInformation
SVGPathSeg
webkitIDBDatabaseError
Int32Array
CSSStyleDeclaration
HTMLLabelElement
SVGPaint
HTMLOutputElement
UIEvent
CSSValueList
SVGPathSegCurvetoQuadraticSmoothAbs
SVGComponentTransferFunctionElement
XMLSerializer
SVGLength
HTMLElement
SpeechInputEvent
TextTrackCueList
HTMLHtmlElement
outerWidth
XMLHttpRequestUpload
sessionStorage
Image
SVGTransformList
HTMLTrackElement
SVGAnimateColorElement
PopStateEvent
TrackEvent
webkitURL
SVGStringList
HTMLIsIndexElement
SVGCircleElement
SVGSymbolElement
SVGTransform
HTMLDocument
HTMLTableColElement
SVGPreserveAspectRatio
Float64Array
KeyboardEvent
CSSPrimitiveValue
SVGPathSegMovetoRel
NodeFilter
OfflineAudioCompletionEvent
XPathEvaluator
SVGPathSegLinetoVerticalAbs
SVGAnimatedInteger
HTMLDirectoryElement
Element
HTMLStyleElement
RGBColor
MouseEvent
XPathResult
XMLHttpRequestException
name
WebKitBlobBuilder
HTMLAppletElement
ClientRectList
ArrayBuffer
Worker
HTMLMeterElement
SVGGElement
EntityReference
HTMLTextAreaElement
ProgressEvent
RangeException
DocumentType
Uint8Array
HTMLCanvasElement
SVGScriptElement
SVGTextPositioningElement
SVGPathSegCurvetoCubicSmoothAbs
BeforeLoadEvent
closed
SVGFontFaceSrcElement
SVGStopElement
Document
webkitAudioContext
offscreenBuffering
CSSCharsetRule
WebKitCSSTransformValue
MutationEvent
SVGPathSegLinetoRel
SVGPathSegLinetoHorizontalAbs
SVGAnimatedLengthList
Clipboard
SVGStyleElement
SVGException
SVGMarkerElement
SVGAltGlyphItemElement
CSSMediaRule
HTMLLinkElement
SVGPolygonElement
SVGClipPathElement
SVGMissingGlyphElement
MessageChannel
SVGSVGElement
TextMetrics
HTMLBRElement
styleMedia
XMLDocument
HTMLPreElement
TimeRanges
HTMLProgressElement
SVGPathSegClosePath
SVGLengthList
SVGAnimatedTransformList
SVGElementInstance
DOMStringMap
console
HTMLSourceElement
HTMLOListElement
HTMLFieldSetElement
SVGFESpecularLightingElement
SVGFEFuncRElement
SVGPathSegCurvetoQuadraticSmoothRel
SVGMatrix
FileReader
WebGLRenderingContext
WebKitFlags
SVGRect
SVGDescElement
CloseEvent
AudioProcessingEvent
CanvasPattern
defaultstatus
Plugin
SVGMPathElement
MimeTypeArray
HTMLMenuElement
WebGLShader
SVGMaskElement
WebKitCSSKeyframesRule
SVGPathSegArcAbs
HTMLHRElement
HTMLTitleElement
WebKitCSSMatrix
self
XMLHttpRequestProgressEvent
SVGFEPointLightElement
HTMLEmbedElement
MediaStreamEvent
HTMLFormElement
EventException
CSSValue
WebGLUniformLocation
HTMLSelectElement
WebGLContextEvent
HTMLMarqueeElement
SVGPathSegList
HTMLButtonElement
SVGGlyphElement
CharacterData
SVGTextPathElement
innerHeight
WebGLFramebuffer
SVGPathSegCurvetoCubicRel
HTMLBodyElement
Option
DOMImplementation
Rect
Audio
screenTop
HTMLAudioElement
opener
SVGPathSegMovetoAbs
SVGFontFaceNameElement
SVGPathSegLinetoHorizontalRel
SVGAnimateElement
ErrorEvent
SVGFEImageElement
TextEvent
XPathException
SVGEllipseElement
HTMLQuoteElement
SVGGradientElement
SVGFEDisplacementMapElement
SVGGlyphRefElement
SVGAnimatedLength
Event
PluginArray
XSLTProcessor
SVGVKernElement
Counter
HTMLParamElement
SVGFontFaceUriElement
SVGPathSegArcRel
toolbar
length
HTMLPropertiesCollection
Storage
webkitIDBFactory
SVGPathSegCurvetoQuadraticRel
HTMLOptGroupElement
HTMLHeadElement
history
CSSRule
SVGFEComponentTransferElement
HTMLAreaElement
DataView
ononline
onprogress
ondragover
onemptied
onpagehide
onmouseout
onloadstart
onwebkitanimationend
onwebkitanimationstart
oncanplay
onsearch
onload
onmousemove
ondblclick
onended
onmessage
onwebkitanimationiteration
onselect
onclick
onloadedmetadata
focus
onbeforeunload
ondragleave
onkeydown
sogouClose
onchange
ondeviceorientation
oncanplaythrough
onkeyup
onloadeddata
onresize
onwebkittransitionend
ondrop
onsuspend
ondragend
onwaiting
onabort
oninput
onseeking
onunload
onstorage
onhashchange
onplay
onreset
ondrag
close
onstalled
onseeked
onpopstate
ondragenter
onpageshow
onmouseup
ontimeupdate
onerror
onsubmit
blur
onpause
postMessage
webkitPostMessage
onmouseover
onkeypress
onplaying
onmousewheel
onoffline
oncontextmenu
onfocus
onscroll
onratechange
oninvalid
onmousedown
ondurationchange
ondragstart
onblur
onvolumechange
getSelection
print
stop
open
showModalDialog
alert
confirm
prompt
find
scrollBy
scrollTo
scroll
moveBy
moveTo
resizeBy
resizeTo
matchMedia
setTimeout
clearTimeout
setInterval
clearInterval
webkitRequestAnimationFrame
webkitCancelRequestAnimationFrame
atob
btoa
addEventListener
removeEventListener
captureEvents
releaseEvents
SgActiveXObject
SgInjectCSS
getComputedStyle
getMatchedCSSRules
webkitConvertPointFromPageToNode
webkitConvertPointFromNodeToPage
openDatabase
webkitRequestFileSystem
webkitResolveLocalFileSystemURL
dispatchEvent
TEMPORARY
PERSISTENT