commit by magit in emacs@2022-09-14 18:02:53
This commit is contained in:
parent
37fc324f9b
commit
75aeebef25
18
js/freq.ts
18
js/freq.ts
|
@ -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]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue