Possible Duplicate:
Using HTML comment tag <!— --> still relevant around JavaScript code?
Kind of remember <!-- //-->
is used to prevent JavaScript code from being displayed in a lower version of IE. Anyone can provide a link to the article explaining this? Hard to search "<!--
" in Google, because it's got stripped off.
And do we still need this in JavaScript block?
Thanks!
Answer: Use the indexOf() Method You can use the indexOf() method in conjugation with the push() remove the duplicate values from an array or get all unique values from an array in JavaScript.
The Set object lets you store unique values of any type, whether primitive values or object references. you are passing new object not reference so it is allowing to add duplicate.
1) Remove duplicates from an array using a SetThe new Set will implicitly remove duplicate elements. Then, convert the set back to an array.
To prevent adding duplicates to an array:Use the Array. includes() method to check if the value is not present in the array. If the value is not present, add it to the array using the push() method. The array will not contain any duplicate values.
Those comments were used when Javascript was first introduced. They are not needed any more, and haven't been for quite a while.
The purpose was to hide the script from browsers that didn't even know what the script
tag was for. Those browsers would ignore the script tag and show the code inside as regular HTML content.
There are no browsers left that don't know about the <script>
tag, so even if they don't run the script, they still don't show the code inside.
Only if you're worried about time-travellers from somewhere back in last milennium coming to the present day with their old computers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With