Can someone help me with my code? I am struggling to prevent duplicate data from being saved into an array. When I click on any two paragraph elements, the text inside them gets added to an array named `test`. However, I want to avoid saving the same text if I click on a paragraph twice. How can I achieve this and prevent duplicate entries in the array?
var test = [];
[...document.querySelectorAll(".container")].forEach(div => div.addEventListener("click", function(e) {
if (e.target.tagName === "P") {
test.push(e.target.textContent);
}
console.log(test);
}));
<div class="container">
<p>
<b>Group:N</b>Code:1234<br/>
<b> Session Type:CS<br/>
<b> Location:Main Hall<br/>
<b>Time:14:00<br/>
<b>Day:Tuesday<br/>
<b>Duration:1hour<br/>
</p>
</div>
<div class="container">
<p>
<b>Group:M</b>Code:98743<br/>
<b> Session Type:NP<br/>
<b> Location:Main Hall2<br/>
<b>Time:11:00<br/>
<b>Day:Monday<br/>
<b>Duration:1hour<br/>
</p>
</div>