_.escape(string) This function converts the characters &, , “, `, and ‘ into their HTML escaped versions &, <, >, ", ` and ' <!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 &, <, >, ", …
Continue reading Underscore.js escape and unescape functionsUnderscore.js
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 …
Continue reading Underscore.js filter() functionUnderscore.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 …
Continue reading Underscore.js each() function