commit by magit in emacs@2022-09-14 18:02:53

This commit is contained in:
Aborn Jiang 2022-09-14 18:02:54 +08:00
parent 37fc324f9b
commit 75aeebef25
1 changed files with 18 additions and 0 deletions

View File

@ -17,3 +17,21 @@ Math.ceil(.95) // 1
// 给定数字的值四舍五入到最接近的整数。
Math.round(20.49); //20
Math.round(20.5); //21
// For iterating on keys of Arrays, Strings, or Objects, use for .. in :
for (let key in yourobject) {
console.log(key, yourobject[key]);
}
// With ES6, if you need both keys and values simultaneously, do
for (let [key, value] of Object.entries(yourobject)) {
console.log(key, value);
}
// To avoid logging inherited properties, check with hasOwnProperty :
for (let key in yourobject) {
if (yourobject.hasOwnProperty(key)) {
console.log(key, yourobject[key]);
}
}