Skip to content

Latest commit

 

History

History
51 lines (31 loc) · 876 Bytes

File metadata and controls

51 lines (31 loc) · 876 Bytes

for...in

功能

逐一提取鍵(key)。

The for...in statement iterates over all enumerable properties of an object that are keyed by strings (ignoring ones keyed by Symbols), including inherited enumerable properties.

Note: for...in should not be used to iterate over an Array where the index order is important.

for...in

範例

const object = { a: 1, b: 2, c: 3 };

for (const property in object) {
  console.log(`${property}: ${object[property]}`);
}

// expected output:
// "a: 1"
// "b: 2"
// "c: 3"

let jewels = { A:true, B:true, C:true };
let stones = "ABc";
let count = 0;

for (const s of stones) {
  if(s in jewels){
	++count;
	}
}

console.log(count);

// 2