JavaScript에서 랜덤 id 생성하기

임의의 id 문자열을 생성하는 함수를 만들어 봅시다:

javascriptfunction getId(length = 16) {
  let chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  
  let res = '';
  
  for (let i = 0; i < length; i++) {
    res += chars[Math.floor(Math.random() * chars.length)];
  }
  
  return res;
}

우리가 만든 함수를 사용해 보겠습니다:

javascriptlet id = getId();
console.log(id);
Задание 1

주어진 함수를 복사하고 동작을 확인해 보세요.