Example 1 — Basic length
Count attributes on an element (MDN-style).
const pre = document.querySelector("pre");
const attrMap = pre.attributes;
console.log(attrMap.length);
// e.g. 3 for class, id, contenteditable How It Works
- Select the element. Any Element has an
attributesmap. - Read
length. One number — how many Attrs are stored. - No assignment. You cannot write
map.length = 0. - Count only. Names/values come from
item()orgetNamedItem().

