JavaScript, 객체의 프로퍼티 개수 얻기

Object 타입의 객체에 대한 프로퍼티의 개수를 얻기 위해서 다음처럼 접근할 수 있습니다.

const obj = { .... };

let result = 0;
for (let fid in rows) {
  result++;
}

느낌이 쎄합니다. 다행히 다음과 같은 매우 효과적인 방식이 있습니다.

Object.keys(obj).length

바닐라 JS의 동적 스크립트 임포팅

바닐라 JS로 어떤 라이브러리를 동적으로 포함하고 해당 라이브러리가 완전히 로딩되었을때 코드를 실행하는 방식

const url = "https://~.min.js";
const htmlMeshScript = document.createElement("script");

htmlMeshScript.type = "module";
htmlMeshScript.src = url;

document.body.appendChild(htmlMeshScrip);

htmlMeshScript.onload = (event) => {
  console.log("loaded");
};