标签:
var items = new Set();
items.add(5);
items.add("5");
console.log(items.size()); // 2
var items = new Set();
items.add(5);
items.add("5");
items.add(5); // oops, duplicate - this is ignored
console.log(items.size()); // 2
var items = new Set([1, 2, 3, 4, 5, 5, 5, 5]);
console.log(items.size()); // 5
var items = new Set();
items.add(5);
items.add("5");
console.log(items.has(5)); // true
console.log(items.has(6)); // false
var items = new Set();
items.add(5);
items.add("5");
console.log(items.has(5)); // true
items.delete(5)
console.log(items.has(5)); // false
var items = new Set([1, 2, 3, 4, 5]);
for (let num of items) {
console.log(num);
}
// element gets converted to a string
var data = {},
element = document.getElementById("my-div");
data[element] = metadata;
var map = new Map();
map.set("name", "Nicholas");
map.set(document.getElementById("my-div"), { flagged: false });
// later
var name = map.get("name"),
meta = map.get(document.getElementById("my-div"));
var map = new Map([ ["name", "Nicholas"], ["title", "Author"]]);
for (let key of map.keys()) {
console.log("Key: %s", key);
}
for (let value of map.values()) {
console.log("Value: %s", value);
}
for (let item of map.items()) { 这个是默认的
console.log("Key: %s, Value: %s", item[0], item[1]);
}
// same as using map.items()
for (let item of map) {
console.log("Key: %s, Value: %s", item[0], item[1]);
}
var reporter = {
report: function(key, value) {
console.log("Key: %s, Value: %s", key, value);
}
};
map.forEach(function(value, key, map) {
this.report(key, value);
}, reporter);
for (let key in object) {
// make sure it‘s not from the prototype or a function!
if (object.hasOwnProperty(key) && typeof object[key] !== "function") {
console.log("Key: %s, Value: %s", key, object[key]);
}
}
标签:
原文地址:http://www.cnblogs.com/chuangweili/p/5162966.html