{"id":15,"date":"2013-10-01T18:30:00","date_gmt":"2013-10-01T18:30:00","guid":{"rendered":"\/blog\/blog\/AngularJS_Underscore_ultimate_web_development.html"},"modified":"2013-10-01T18:30:00","modified_gmt":"2013-10-01T18:30:00","slug":"angularjs-underscore-the-ultimate-web-development-toolkit","status":"publish","type":"post","link":"https:\/\/mohammedlakkadshaw.com\/blog\/angularjs-underscore-the-ultimate-web-development-toolkit.html","title":{"rendered":"AngularJS + Underscore The ultimate web-development toolkit (2018)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Before starting my latest web-development project I was looking for some robust javascript frameworks that I could use. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I was familiar with AngularJS and I loved it, but it doesn\u2019t have a lot of utility methods and I was looking for some solution to solve that problem.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So, I thought about using UnderscoreJS, which is a collection of utility methods with angularJS and I got myself a killer web development toolkit. In this blog post<g class=\"gr_ gr_50 gr-alert sel gr_gramm gr_replaced gr_inline_cards gr_disable_anim_appear Punctuation only-ins replaceWithoutSep\" id=\"50\" data-gr-id=\"50\">,<\/g> I have summed up UnderscoreJS methods which I find useful. visit <a href=\"http:\/\/underscorejs.org\/#\">underscorejs.org<\/a> to view all the available methods.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"using-underscore-with-angular\">Using Underscore with Angular:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Combining angular and underscore is pretty straightforward, just add import underscore in your index.html, then add it as a service.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And then we could inject it into our controllers.<br\/><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"useful-underscore-methods\">Useful Underscore methods:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I have compiled a list of my favourite underscoreJS methods, you can always visit <a href=\"http:\/\/underscorejs.org\/\">underscorejs.org<\/a> to view all the methods that are available in underscore.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>_.isUndefined:<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><br\/>This method is used to determine whether the specified value is undefined or not, I know you could always do <strong><g class=\"gr_ gr_5 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace\" id=\"5\" data-gr-id=\"5\">typeof<\/g> value === \u201cundefined\u201d<\/strong> to check whether it is undefined or not, but I find this neater.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\t_.isUndefined(value)\n=>\n(Returns a boolean value true\/false)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>_.defaults:<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><br\/>This is also a very useful method, it allows <g class=\"gr_ gr_5 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins replaceWithoutSep\" id=\"5\" data-gr-id=\"5\">you<\/g>\u00a0to define default values for something if they are not present.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var data = {\"model\":\"T\", \"manufacturer\": \"Ford\", \"price\": \"200\"};\n_.defaults(data, {\"model\":\"N\/A\", \"N\/A\": \"Ford\", \"price\": \"0\"})\n\noutput: ---> {\"model\":\"T\", \"manufacturer\": \"Ford\", \"price\": \"200\"}\n\n_.defaults({},{\"model\":\"N\/A\", \"N\/A\": \"Ford\", \"price\": \"0\"})\t\noutput: ---> {\"model\":\"N\/A\", \"N\/A\": \"Ford\", \"price\": \"0\"}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"where\"><strong>_.where:<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This method comes handy when you want to search something in the array of objects using some attributes present in the object.<br\/>consider the example below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var data = [{'model':\"T\", 'manufacturer':'Ford'},{'model':\"P\", 'manufacturer':'Ford'},{'model':\"E\", 'manufacturer':'Ford'},{'model':\"a\", 'manufacturer':'GM'},{'model':\"g\", 'manufacturer':'GM'}];\nSo,\n_.where(list, properties) \n_.where(data, {'manufacturer':'ford'})\n=>[{'model':\"T\", 'manufacturer':'Ford'},{'model':\"P\", 'manufacturer':'Ford'},{'model':\"E\", 'manufacturer':'Ford'}]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><br\/><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"uniq\"><strong>_.uniq:<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This method operates on arrays, and it removes duplicates in the array.<br\/>Consider the following example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>_.uniq(array, [isSorted], [iteratee])<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>_.uniq(['Tim','Jon','Jim','Tim']);\n=> ['Tim','Jon','Jim'];<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><br\/><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>_.pluck:<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><br\/>if you ever wanted to extract some values from an array of objects, well the pluck method <g class=\"gr_ gr_5 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace\" id=\"5\" data-gr-id=\"5\">let\u2019s<\/g> you do that.<br\/>Here is the example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var people = [{name:'Joe', hobby:'baseball'}, {'Jane', hobby:'swimming'}, {'Tim', Hobby:'basketball'}, {'Duke', hobby:'cricket'}];\n\n-.pluck(people,'name');\n=>['Joe','Jane','Tim','Duke']<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">By merging these two awesome web development frameworks together we can get a pretty nice web development experience, as angular serves as an awesome MVC, and underscore provides a very useful collection of utility methods.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">About me:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I am Mohammed Lakkadshaw. A freelance javascript developer with expertise in NodeJs Angular and React. If you like this article please share them on Twitter Facebook and Google+.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Before starting my latest web-development project I was looking for some robust javascript frameworks that I could use. I was familiar with AngularJS and I loved it, but it doesn\u2019t have a lot of utility methods and I was looking for some solution to solve that problem. So, I thought about using UnderscoreJS, which is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,5],"tags":[],"class_list":["post-15","post","type-post","status-publish","format-standard","hentry","category-angularjs","category-javascript"],"_links":{"self":[{"href":"https:\/\/mohammedlakkadshaw.com\/blog\/wp-json\/wp\/v2\/posts\/15","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mohammedlakkadshaw.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohammedlakkadshaw.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohammedlakkadshaw.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohammedlakkadshaw.com\/blog\/wp-json\/wp\/v2\/comments?post=15"}],"version-history":[{"count":0,"href":"https:\/\/mohammedlakkadshaw.com\/blog\/wp-json\/wp\/v2\/posts\/15\/revisions"}],"wp:attachment":[{"href":"https:\/\/mohammedlakkadshaw.com\/blog\/wp-json\/wp\/v2\/media?parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohammedlakkadshaw.com\/blog\/wp-json\/wp\/v2\/categories?post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohammedlakkadshaw.com\/blog\/wp-json\/wp\/v2\/tags?post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}