Set.prototype.size
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2015å¹´7æ.
size 㯠Set ã¤ã³ã¹ã¿ã³ã¹ã®ã¢ã¯ã»ãµã¼ããããã£ã§ããã®éåå
ã®ï¼åºæã®ï¼è¦ç´ ã®æ°ãè¿ãã¾ãã
試ãã¦ã¿ã¾ããã
const set = new Set();
const object = {};
set.add(42);
set.add("forty two");
set.add("forty two");
set.add(object);
console.log(set.size);
// äºæ³ãããçµæ: 3
解説
size ã®å¤ã¯ãSet ãªãã¸ã§ã¯ããããã¤ã®è¦ç´ ãæã¤ããè¡¨ãæ´æ°å¤ã§ããsize ã«å¯¾ããã»ããã¢ã¯ã»ãµã¼é¢æ°ã¯ undefined ã§ãããã£ã¦ããã®ããããã£ã¯å¤æ´ã§ãã¾ããã
ä¾
>size ã®ä½¿ç¨
js
const mySet = new Set();
mySet.add(1);
mySet.add(5);
mySet.add("some text");
console.log(mySet.size); // 3
仿§æ¸
| Specification |
|---|
| ECMAScript® 2027 Language Specification> # sec-get-set.prototype.size> |