element.hasAttribute(attributeName)
<video src="video.mp4" autoplay></video>
const myVideo = document.querySelector("video");

console.log(myVideo.hasAttribute("src")); // true
console.log(myVideo.hasAttribute("autoplay")); // true
console.log(myVideo.hasAttribute("loop")); // false
<a href="https://example.com">example.com</a>
<a href="https://example.com">example.com</a>
<a href="https://example.com">example.com</a>
// ドキュメント内のすべてのa要素を取得
const anchorEle = document.querySelectorAll("a");

// それぞれの要素を順番に処理する - forEach()関数を適用
anchorEle.forEach(ele => {
    // href属性がある場合
    if (ele.hasAttribute("href")) {
        // 新しいウィンドウで開くリンクに変更
        ele.setAttribute("target", "_blank");
        
        // 新しいウィンドウで開く際のセキュリティに関するrel属性の値を設定
        ele.setAttribute("rel", "noopener noreferrer");
    }
});
<a href="https://example.com" target="_blank" rel="noopener noreferrer">
    example.com
</a>
<a href="https://example.com" target="_blank" rel="noopener noreferrer">
    example.com
</a>
<a href="https://example.com" target="_blank" rel="noopener noreferrer">
    example.com
</a>