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>
// Find all <a> elements in the document
const anchorEle = document.querySelectorAll("a");

// Iterate through each element using the forEach() function
anchorEle.forEach(ele => {
    // If the element has an href attribute
    if (ele.hasAttribute("href")) {
        // Make the link open in a new tab
        ele.setAttribute("target", "_blank");

        // Apply the rel attribute for security when opening in a new tab
        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>