# forEach * forEach() 方法會將陣列內的每個元素,皆傳入並執行給指定的函式一次。 * 可用來取代 for 的寫法,讓程式碼更簡短,省略掉定義 i、arr.length…等動作。 ### 語法 > array.forEach(function(currentValue, index, arr), thisValue) | 參數 | 描述 | | -------- | -------- | | currentValue | 常用參數 / 當前元素 | | index | 選用參數 / 當前元素索引值 | | arr | 選用參數 / 當前元素的數組對象 | > forEach() 沒有第二參數thisArg 的範例 >  ###### 沒有第二參數 thisArg 的結果顯示為 : 6 # > forEach() 有第二參數thisArg 的範例 > 第二個參數 thisArg 是可選擇性的,如果有這個參數,它就會被作為 callback 回呼函式,每次被調用的 this 的值。  ###### 有第二參數 thisArg 的結果顯示如下 : 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up