NamedNodeMap.item()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

item()NamedNodeMap インターフェイスのメソッドで、マップ内の指定された位置にある項目を返します。

メモ: このメソッドは、 [] 演算子の構文を使用した場合にも呼び出されます。 そのため i が数値の場合、 myMap[i]myMap.item(i) と同じです。

構文

js
item(index);
[index];

引数

index

返したい項目の位置を表す数値です。

返値

Attr です。数値がマップの length 以上の場合は null です。

html
<pre zero="test" one="test" two="test"></pre>
js
const pre = document.getElementsByTagName("pre")[0];
const attrMap = pre.attributes;

pre.textContent = `The attribute map contains:
0: ${attrMap.item(0).name}
1: ${attrMap[1].name}
2: ${attrMap.item(2).name}`;

仕様書

Specification
DOM
# dom-namednodemap-item

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
item

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support