Underscore.js escape and unescape functions

_.escape(string) This function converts the characters &, , “, `, and ‘ into their HTML escaped versions &amp;, &lt;, &gt;, &quot;, &#96; and &#x27; <!DOCTYPE html> <html>     <head>     <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore.js"></script>         <script type="text/javascript">             var str = "<html>topjavatutorial.com</html>";             var escapedStr = _.escape(str);             console.log(escapedStr);         </script>     </head> </html> Output: _.unescape(string) The opposite of escape, replaces &amp;, &lt;, &gt;, &quot;, […]

Underscore.js filter() function

Underscore.js _.filter() Underscore.js _.filter() is used to filter elements from a list that match certain condition. The full function signature is _.filter(list, predicate, [context]). The second function parameter “predicate” is a function that provides the filter logic.   The following example filters even numbers from an array. <!DOCTYPE html> <html>     <head>     <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore.js"></script>                  <script […]

Underscore.js each() function

Underscore.js _.each() Underscore each function is used to iterate over a list of elements. The full function signature is _.each(list, iteratee, [context]). The second function parameter “iteratee” is a function and will be called against each item of the iterated list object or array passed as its first argument. Each invocation of iteratee is called […]