Here is my code. I am badly stuck to figure out how to prevent saving duplicate data into an array. Basically,when i click on any two of paragraph elements then the text contain in paragraph saved into an array called test.But, I want, when I click any paragraph twice then text must not be saved into an array.I want to prevent any duplicate entry.
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>