# 【JS】小知識 - foreach(functionName) * 原來foreach後面可以包一個function呢 * ~~大驚小怪~~ ```javascript const numbers = [45, 4, 9, 16]; let txt = ""; numbers.forEach(myFunction); document.getElementById("demo").innerHTML = txt; function myFunction(value, index, array) { txt += value + "<br>"; } // 45 4 9 16 ``` --- # 【JS】小知識 - for / in 是什麼? * for…in用來迭代Object中enumerable的屬性 * 遞迴該Object的prototype中enumerable的屬性 ```javascript Object.prototype.objCustom = function() {} Array.prototype.arrCustom = function() {} const iterable = [3, 5, 7] iterable.foo = 'hello' for (const i in iterable) { console.log(i) } // 0, 1, 2, "foo", "arrCustom", "objCustom" ```
×
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