1<script>
2var encodedStr = "This is fun & stuff";
3var decoded = $("<div/>").html(encodedStr).text();
4console.log(decoded);
5</script>
6
7<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
8<div/>
1var encodedStr = "This is fun & stuff";
2var decoded = $("<div/>").html(encodedStr).text();
3console.log(decoded);
4
5
6<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
7<div/>
8
1function decodeEntities(encodedString) {
2 var textArea = document.createElement('textarea');
3 textArea.innerHTML = encodedString;
4 return textArea.value;
5}
6
7console.log(decodeEntities('1 & 2')); // '1 & 2'