コメントはコード内にあります (すべてのアイテムがループ内の条件を満たしているかどうかを確認し、そうであればアクションを実行する方法がわかりません):
// 編集 - より現実的な例。
実際の例は非常に複雑なので、ページ リンク (またはページ上の任意の html 要素) をテストするとします。
HTML:
<html>
<head>
<title>Links test</title>
</head>
<body>
<!-- links are random - we do not know how many they are, and how many of them got title attribute -->
<a href="https://www.google.com" title="google">google</a>
<a href="https://facebook.com/">facebook<</a>
<a href="https://www.instagram.com/" title="instagram">instagram</a>
<a href="https://www.amazon.com/">amazon</a>
<a href="https://www.apple.com/" title="apple">apple</a>
</body>
</html>
JS:
let links = document.getElementsByTagName('a');
let linksLength = links.length;
let titleCount = 0;
for (i = 0; i < linksLength; i++) {
if (links[i].getAttribute('title') !== undefined) {
// I need to count all loop part that fulfil the condition
titleCount += 1;
// and if it's the last item that fulfil this condition then do something (in this main loop)
}
}