[Javascript] 배열의 length & Set 객체의 size

manddu·2023년 1월 31일
post-thumbnail

Array.length (Array.prototype.length)란?

  • Array인스턴스length속성은 배열의 길이를 반환한다.
  • length 속성에 값을 설정할 경우, 배열의 길이를 변경할 수 있다.
const clothing = ['shoes', 'shirts', 'socks', 'sweaters'];

console.log(clothing, clothing.length);
// Expected output: 4

clothing.length = 1;
console.log(clothing, clothing.length);
// Expected output: Array ["shoes"] 1

Set.prototype.size란?

  • Set 객체size 접근자 속성은 Set 객체의 원소 수를 반환한다.
  • size값의 설정자는 undefined이다. 즉, size값을 직접 변경할 수 없다.
var mySet = new Set();
mySet.add(1);
mySet.add(5);
mySet.add('some text')

mySet.size; // 3

참조
Array.length 더 알아보기
Set.size 더 알아보기

profile
쉽게 터지지 않아요.

0개의 댓글