<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Madhava Kumar Ippili on Medium]]></title>
        <description><![CDATA[Stories by Madhava Kumar Ippili on Medium]]></description>
        <link>https://medium.com/@madhavmahesh?source=rss-4ceccb7a9200------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7W9ILTyl6k3MhSqw7tLB4Q.jpeg</url>
            <title>Stories by Madhava Kumar Ippili on Medium</title>
            <link>https://medium.com/@madhavmahesh?source=rss-4ceccb7a9200------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 09:12:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@madhavmahesh/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[LoopBack 4 Decorators]]></title>
            <link>https://medium.com/@madhavmahesh/loopback-4-decorators-caa5c36c8590?source=rss-4ceccb7a9200------2</link>
            <guid isPermaLink="false">https://medium.com/p/caa5c36c8590</guid>
            <category><![CDATA[loopback4]]></category>
            <category><![CDATA[swagger]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[decorators]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Madhava Kumar Ippili]]></dc:creator>
            <pubDate>Sun, 09 Jul 2023 13:07:00 GMT</pubDate>
            <atom:updated>2023-07-09T13:07:00.618Z</atom:updated>
            <content:encoded><![CDATA[<p>As discussed in the previous article, LoopBack as a Framework, provides lot of decorators to make developer life easier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*uoDMMTN5AjapAu4Xc2f5mQ.png" /></figure><p>A decorator allows you to annotate or modify your class declarations and members with metadata. Decorators give the flexibility/ add’s a flavor to the plain classes/parameters to better understand by the framework.</p><p>LoopBack 4 decorators are classified into 4 categories as below:</p><pre>1) OpenAPI Decorators<br>2) Dependency Injection Decorator<br>3) Authentication Decorator<br>4) Repository Decorators</pre><h4>1) OpenAPI Decorators:</h4><p>@api : It is used to define the path of the API. Helps to define various options of the controller such as path, parameters, different response of the API, response schemas.</p><p>@operation : It is used as a controller level method decorator. It helps to specify the verb, path, parameters, and response as a specification of the API endpoint.</p><p>@get,@post,@put,@patch,@del : These are the operation level decorator to handle the get, post, put, patch, del related API calls.</p><p>@param : is applied to controller method parameters to generate on the Swagger.</p><p>@requestBody : is applied to a controller method parameter to generate OpenAPI requestBody specification for it.Only one parameter can be decorated by @requestBody per controller method.</p><h4>2) Dependency Injection Decorator:Dependency Injection Decorators</h4><pre>@inject<br>@inject.getter<br>@inject.setter<br>@inject.binding<br>@inject.tag<br>@inject.view<br>@inject.context</pre><p>@inject : is a decorator to annotate class properties or constructor arguments for automatic injection by LoopBack’s IoC container.</p><p>@inject.getter : injects a getter function that returns a promise of the bound value of the key.</p><p>@inject.setter : injects a setter function to set the bound value of the key.</p><p>@inject.binding : injects a binding for the given key. It can be used to bind various types of value providers to the underlying binding or configure the binding.</p><p>@inject.tag : injects an array of values by a pattern or regexp to match binding tags.</p><p>@inject.view : injects a ContextView to track a list of bound values matching a filter function.</p><p>@inject.context : injects the current context.</p><h4>3) Authentication Decorator:</h4><p>@authenticate : decorator to handle the authentication. And this decorator can be used in 3 ways:</p><pre>1) Method level,<br>2) class level,<br>3) multiple strategies.</pre><h4>4) Repository Decorators:</h4><p>@model : Decorator applied to a class to define the entity.</p><p>@property : To define the meta data of the property in the model.</p><p>@repository : This decorator either injects an existing repository or creates a repository from a model and a datasource.</p><p>@relation : To establish relation between 2 models.</p><p>@belongsTo : Many-to-one or one-to-one connection between models.</p><p>@hasOne : One-to-one connection between models.</p><p>@hasMany : One-to-many connection between models.</p><p>@referencesMany: Relation embeds an array of foreign keys to reference other objects.</p><p>And some of the upcoming decorators:</p><ul><li>@embedsOne</li><li>@embedsMany</li><li>@referencesOne</li><li>@referencesMany</li></ul><p>Happy reading, decorating and coding!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=caa5c36c8590" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LoopBack 4 Building Blocks]]></title>
            <link>https://medium.com/@madhavmahesh/loopback-4-building-blocks-d153b81580c9?source=rss-4ceccb7a9200------2</link>
            <guid isPermaLink="false">https://medium.com/p/d153b81580c9</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[loopback]]></category>
            <category><![CDATA[theory]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Madhava Kumar Ippili]]></dc:creator>
            <pubDate>Sun, 09 Jul 2023 11:48:19 GMT</pubDate>
            <atom:updated>2023-07-09T11:55:33.312Z</atom:updated>
            <content:encoded><![CDATA[<p>In the previous article we discussed about installing and building a small API end point.</p><p>LoopBack as a framework has lot of inbuilt features to solve different way’s or usescases of API/MicroService. This article helps in understanding the building blocks of LoopBack 4 Framework. How to implement the routine uses cases while implementing an API/MicroService such as building, logging, error handling, DB connecting, routing, aspect-oriented Programming in LoopBack 4 Framework.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J6kcFu4A2ehAh6osGVlkzQ.png" /></figure><p>Now, let&#39;s discuss the different building blocks or the mechanism or how a business logic is split into layers, in the API flow within the LoopBack 4. LoopBack 4 comprises of below building blocks to represent different responsibilities for typical API and/or Microservice applications.</p><pre>LoopBack 4 Building blocks:<br>1) Application<br>2) Server<br>3) Controller<br>4) Interceptor<br>5) Route<br>6) Sequence<br>7) Model<br>8) DataSource<br>9) Repository<br>10) Relation<br>11) Decorator</pre><h3><strong>1) Application:</strong></h3><ul><li>This is the central class which would contain the settings of all the module’s components, controllers, servers and bindings.</li><li>The application class extends the Context and provides the controllers for starting and stopping the server.</li></ul><p>The Application class helps in setting up the below configuration:</p><pre>Logging.<br>Environment based configuration.<br>Application context path<br>Setting up port no.<br>Setting up a host.</pre><h3>2) Server:</h3><ul><li>Server defines the minimal required functions (start and stop) and a ‘listening’ property to implement for a LoopBack application.</li><li>These are used to represent implementation for inbound transports and/or protocols such as REST over http, gRPC over http2, graphQL over https, etc.</li><li>They typically listen for requests on a specific port, handle them, and return appropriate responses.</li><li>A single application can have multiple server instances listening on different ports and working with different protocols.</li></ul><p>Below set of tasks can be acheived through the server interface:</p><pre>Enabling HTTPS.<br>Creating own servers<br>Customizing Open API SPEC<br>Customizing Server related configuration.</pre><h3>3) Controller:</h3><ul><li>Its a class, which would implement all the operations of the API.</li><li>Stands as a bridge between the API endpoint to take the request and DB service to get the required result and return it back.</li></ul><pre>Handles API Request &amp; Response validations.<br>Uses AJV validation library.</pre><h3>4) Interceptor:</h3><p>These are re-usable functions to provide aspect-oriented logic around method invocations.</p><pre>Use cases:<br>Add extra logic before/after method invocations.<br>Validate or transform arguments.<br>Validate or transform return values.<br>Catch/transform error&#39;s.<br>Override method invocations.</pre><h3>5) Route:</h3><p>Mapping between API and operation. It tells LoopBack which operator to invoke () when given a HTTP Request.</p><h3><strong>6) Sequence:</strong></h3><p>A stateless grouping of actions that control how a Server responds to requests.</p><p>A Sequence is a series of steps to control how a specific type of Server responds to incoming requests.</p><p>Each types of servers, such as RestServer, GraphQLServer, GRPCServer, and WebSocketServer, will have its own flavor of sequence.</p><p>The sequence represents the pipeline for inbound connections.</p><h3>7) Model:</h3><p>A model describes business domain objects, for example, Customer, Address, and Order. It usually defines a list of properties with name, type, and other constraints.</p><h3>8) DataSource:</h3><p>A DataSource in LoopBack 4 is a named configuration for a Connector instance that represents data in an external system. The Connector is used by legacy-juggler-bridge to power LoopBack 4 Repositories for Data operations.</p><h3>9) Repository:</h3><p>A Repository represents a specialized Service interface that provides strong-typed data access (for example, CRUD) operations of a domain model against the underlying database or service.</p><h3>10) Relation:</h3><p>A Repository represents a specialized Service interface that provides strong-typed data access (for example, CRUD) operations of a domain model against the underlying database or service.</p><h3>11) Decorator:</h3><p>The pattern used to annotate or modify your class declarations and their members with metadata.</p><p>Happy Reading!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d153b81580c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Node.js API with LoopBack 4]]></title>
            <link>https://medium.com/@madhavmahesh/node-js-api-with-loopback-4-e0b253666644?source=rss-4ceccb7a9200------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0b253666644</guid>
            <category><![CDATA[loopback]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[swagger]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Madhava Kumar Ippili]]></dc:creator>
            <pubDate>Sat, 08 Jul 2023 18:14:16 GMT</pubDate>
            <atom:updated>2023-07-08T18:14:16.727Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tnL20EXsntjB0jfDzQDC7g.png" /></figure><p>About the LoopBack from the Loopback.io website:</p><p><strong><em>A highly extensible Node.js and TypeScript framework for building APIs and microservices.</em></strong></p><p>Yes, it&#39;s a very very easy and flexible for building API’s and microservices.</p><p>Let’s look at the practical way of installing, buildind an API and consuming it. LoopBack comes with a CLI, that scaffolds a project or an extension by generating the basic code.</p><p>Let’s go step by step, open a terminal and run the below command to install the LoopBack 4 CLI:</p><pre>npm i -g @loopback/cli</pre><p>Now the LoopBack framework is installed in the machine.</p><p>Lets create a new app from the CLI, run the below command:</p><pre>lb4 app</pre><p>This command goes with a interactive questionnaire reg. the app to be created, just provide the details as below:</p><pre> Project name: hellow-world<br> Project description: Hello world example<br> Project root directory: (hellow-world)<br> Application class name: StarterApplication<br> Select features to enable in the project:<br>❯◉ Enable eslint: add a linter with pre-configured lint rules<br> ◉ Enable prettier: install prettier to format code conforming to rules<br> ◉ Enable mocha: install mocha to run tests<br> ◉ Enable loopbackBuild: use @loopback/build helpers (e.g. lb-eslint)<br> ◉ Enable vscode: add VSCode config files<br> ◉ Enable docker: include Dockerfile and .dockerignore<br> ◉ Enable repositories: include repository imports and RepositoryMixin<br> ◉ Enable services: include service-proxy imports and ServiceMixin<br>Starting the project</pre><p>Now the project is created run the below command to run the project:</p><pre>cd hello-world<br>npm start</pre><p>You will observe the code gets compiled and build, and the app would be available at the port 3000 as below:</p><pre>Server is running at http://[::1]:3000<br>Try http://[::1]:3000/ping</pre><p>Open a broswer and load: <a href="http://localhost:3000,">http://localhost:3000,</a> hello-world app would be loaded as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*nhoEm5NPJMWY4ms5HfgdKg.png" /></figure><p>Now click on the /explorer and the swagger gets loaded as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*qumS6GGotF7HXhYDKL33pg.png" /></figure><p>It’s a vow moment, we got the API ready with just a set of commands right. Now you can play with the Swagger and test the API.</p><p>You might have observed, we have not typed any code to build the API, attach the swagger, attach a server and lot other invisible things. All these things were handled by the LoopBack framework only, and we as a developer can just concentrate on building the API.</p><p>Happy Reading!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0b253666644" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mini Website with TypeScript]]></title>
            <link>https://medium.com/@madhavmahesh/mini-website-with-typescript-35794096a9ec?source=rss-4ceccb7a9200------2</link>
            <guid isPermaLink="false">https://medium.com/p/35794096a9ec</guid>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[transpile]]></category>
            <category><![CDATA[html]]></category>
            <dc:creator><![CDATA[Madhava Kumar Ippili]]></dc:creator>
            <pubDate>Sat, 08 Jul 2023 17:32:18 GMT</pubDate>
            <atom:updated>2023-07-08T17:32:18.220Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi all, it&#39;s been so long I have published an article. This time I came up with a mini website built with TypeScript.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ATwXDtIoXtUz14_p" /></figure><p>This is a simple website with a hello world built with TypeScript. Usually till these days we are developing websites with JavaScript, but we still have some problems to handle the types or what type of data is the Method, variable, or a functions uses / accepts / returns. In these cases, its always suggestable to start the development with Typescript.</p><h3>TypeScript is JavaScript with syntax for types.</h3><p>TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale. Definition from <a href="https://www.typescriptlang.org/">TypeScript: JavaScript With Syntax For Types. (typescriptlang.org)</a></p><p>Let&#39;s start building the min-website with TypeScript.</p><p>The setup/software&#39;s required are:</p><ol><li>VS Code — IDE</li><li>Node.js</li></ol><p>With the above minimum setup let&#39;s start, firstly.</p><p>Create a directory and name it as mini-website and load this directory in the VS-Code editor as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9tAP1u0ou8tqH70G7WsT_A.png" /></figure><p>Now open the terminal and run the command: <strong><em>npm i typescript — save-dev </em></strong>and which would look as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*BPQn0qQqpw3btZH1tVbptQ.png" /></figure><p>Now you have got the package.json and typescript installed in the project mini-website directory. (yay!!!)</p><p>Now as we got typescript installed in the project lets initiate a new typescript project with the following command:</p><pre>npx tsc - init</pre><p>Now you can observe the tsconfig.json file created with some default configuration as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n0HtmF9FCOksOxSCRFOCDA.png" /></figure><p>Default configuration:</p><p>Created a new tsconfig.json with:</p><pre>target: es2016<br>module: commonjs<br>strict: true<br>esModuleInterop: true<br>skipLibCheck: true<br>forceConsistentCasingInFileNames: true</pre><p>Now let&#39;s create the index.html in the project root path as below and type ! character in the file and if you observe the VS Code suggests with an Emmet abbreviation, just click enter and you will see default HTML code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nkv75iqgY9I5e2WTOpV0Kg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KGahf4y6Mb3a0gzR7g8Jkw.png" /></figure><p>Now let&#39;s create the typescript file, for this let&#39;s create the directory structure in the following way, with in the root directory: src/scripts/main.ts.</p><p>For this no need to create each directory and file individually, just copy the above path and in the VS Code choose to create a new file and paste the copied path as shown below and click enter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xx7o8KhFYeHVJ5qSHmIXHg.png" /></figure><p>Now you have a blank main.ts file created as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*NdzxeLjiT3g9AiEqNiQ9pw.png" /></figure><p>Copy paste the below code snippet into the main.ts file:</p><pre>const printMe = (): void =&gt; {<br>    return console.log(&quot;Hello World!!!&quot;);<br>};</pre><p>In the index.html paste the below code snippet inside the body tag:</p><pre>&lt;button onclick=&quot;printMe()&quot;&gt;Click here &lt;/button&gt;<br>&lt;script src=&quot;dist/script/main.js&quot;&gt;&lt;/script&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uWHGQx-1hEvK2DnGQLwOKQ.png" /></figure><p>Now if you observe the above html snippet there is a path dist/scripts/main.js, this is path of the transpiled ts file and for this we have to make below configuration changes in the tsconfig.json file:</p><pre>{<br>  &quot;compilerOptions&quot;: {<br>    &quot;target&quot;: &quot;es2016&quot;,<br>    &quot;module&quot;: &quot;commonjs&quot;,<br>    &quot;rootDir&quot;: &quot;src&quot;,<br>    &quot;outDir&quot;: &quot;dist&quot;,<br>    &quot;esModuleInterop&quot;: true,<br>    &quot;forceConsistentCasingInFileNames&quot;: true,<br>    &quot;strict&quot;: true,<br>    &quot;skipLibCheck&quot;: true<br>  }<br>}</pre><p>Now, we are almost at the end of loading the mini-websit, now run the below command to transpile the main.ts file:</p><pre>npx tsc</pre><p>Now you can check the main.js under the dist folder.</p><p>Now just open the index.html in any browser and open the dev tools and then click on the click here button, Hello World would be printed in the console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*mNNw61RzGldScdazh-F4rg.png" /></figure><p>Here comes out mini website with TypeScript.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35794096a9ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The road to Installing Mongo DB]]></title>
            <link>https://medium.com/@madhavmahesh/the-road-to-installing-mongo-db-48f3127211c5?source=rss-4ceccb7a9200------2</link>
            <guid isPermaLink="false">https://medium.com/p/48f3127211c5</guid>
            <category><![CDATA[installation]]></category>
            <category><![CDATA[community-edition]]></category>
            <category><![CDATA[mongodb]]></category>
            <dc:creator><![CDATA[Madhava Kumar Ippili]]></dc:creator>
            <pubDate>Thu, 31 May 2018 01:37:06 GMT</pubDate>
            <atom:updated>2018-05-31T02:41:24.863Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0pJkvGg99CrhiaNREWzg2g.jpeg" /></figure><p>Hi All, This time would like to show the installation of MongoDB in windows machine. MongoDB is one of the famous and proven Document oriented DB in the current era.</p><ol><li>Download the .msi file from the following link. <a href="https://www.mongodb.com/download-center?_ga=2.97553309.304468394.1527693080-1720648127.1513300344#production"><strong>Download</strong></a></li><li>Move to the directory where the downloaded .msi file is present.</li><li>Execute the following command by opening command prompt with Administrator mode in that directory where .msi file is present:</li></ol><pre>msiexec.exe /q /i mongodb-win32-x86_64-2008plus-ssl-3.6.5-signed.msi <br>            INSTALLLOCATION=&quot;C:\Program Files\MongoDB\Server\3.6.5\&quot; <br>            ADDLOCAL=&quot;all&quot;</pre><p>4. After executing the above command, installation is completed. Now the mongoDB got successfully installed.</p><p><strong>Running the Mongo DB:</strong></p><ol><li>Move to the following directory C:\Program Files\MongoDB\Server\3.6.5\</li><li>This is the path where MongoDB got installed, in this directory you can find a directory called bin. Move to /bin directory</li><li>For opening the Server, run the command Mongod</li></ol><pre>mongod --dbpath d:\test\mongodb\data <br>-- For running the server</pre><p>4. For running the client</p><pre>mongo</pre><p>Now you can find 2 command prompts running, the command prompt opened by running the mongo command is the client one, here you can execute the Mongo DB related commands.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48f3127211c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular 6 Component creation for combo box]]></title>
            <link>https://medium.com/@madhavmahesh/angular-6-component-creation-for-combo-box-6b2eec03bece?source=rss-4ceccb7a9200------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b2eec03bece</guid>
            <category><![CDATA[combobox]]></category>
            <category><![CDATA[custom-component]]></category>
            <category><![CDATA[angularjs]]></category>
            <category><![CDATA[components]]></category>
            <dc:creator><![CDATA[Madhava Kumar Ippili]]></dc:creator>
            <pubDate>Tue, 29 May 2018 12:48:18 GMT</pubDate>
            <atom:updated>2018-05-30T18:05:57.644Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cmh8WcXeSyeNYXU8rZKcYw.jpeg" /></figure><p>Hi all, this time I came up with an interesting topic of creating a component…, ah ah ah cool, not a simple component, its a component that we can plan publish to NPM family and use it wherever you want.</p><p>The component I planned to build is a combo box.., Guys worked with Visual Basic might heard of this term. Combo box is the combination of dropdown and a text box to make you understand at its simple. But when we build we will be using only the text and a div to show the drop down.</p><p>The below diagram is the skeleton structure to achieve the combo-box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*Es2XKoC2Hy08WEc6WJOqQg.jpeg" /></figure><p>Combo box = Text box + button + drop down</p><ol><li>A normal input text box.</li><li>A button with a Down side arrow.</li><li>A div that shows the results matching the typed characters in the text box.</li></ol><blockquote>Combo box is a kind of input control which is similar to drop-down with additional feature of searching for the required string.</blockquote><p>Lets see the final build version of the combo-box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*vtQGagi2g4vvkIWowOrtbQ.jpeg" /></figure><ol><li>On click of the button the div expands and shows the available options.</li><li>If we search for the keyword, list shown in the div gets filtered.</li></ol><p>Lets start building the component. Here we will create a new component and use it in the app-component.</p><p><strong>Setup:</strong></p><ol><li>Node version 8</li><li>Angular 6</li><li>Angular CLI 6</li><li>Font awesome CDN path.</li></ol><p>Generate a Angular 6 project with the Angular CLI 6 with the below command.</p><pre>ng new angular6-combo-box</pre><p>This command will create the directory structure and also install’s the required NPM packages.</p><p>Once this command is successful, just to check project running or not give the below command and open the following URL.</p><pre>command: ng serve<br>URL to check in browser: http:\\localhost:4200</pre><p>Now generate a new component called combo-box, for this give the below command in the app directory:</p><pre>ng new component combo-box</pre><p>Now, open the combo-box.component.html file and paste the below:</p><pre>&lt;div class=&quot;combo-container&quot;&gt;<br> &lt;span class=&quot;drop-down&quot;&gt;<br>   &lt;input  type=&quot;text&quot;<br>           class=&quot;input-control&quot;<br>           [ngModel]=&quot;textToSor&quot;<br>           (ngModelChange)=&quot;textChange($event)&quot;<br>           (keyup)=&quot;onKeyDownAction($event)&quot; <br>           (focus)=&quot;onFocusEventAction()&quot;  <br>           (blur)=&quot;onBlurEventAction()&quot;/&gt;</pre><pre>    &lt;button class=&quot;drop-down-button&quot;<br>            (click)=&quot;toogleDropDown()&quot;&gt;<br>            &lt;i class=&quot;fa fa-angle-down&quot;&gt;&lt;/i&gt;<br>    &lt;/button&gt;<br> &lt;/span&gt;<br> &lt;div class=&quot;data-container&quot; *ngIf=&quot;showDropDown&quot;&gt;<br>    &lt;p *ngFor=&quot;let data of dummyDataList; <br>               let i = index&quot; class=&quot;data-list&quot;<br>       (click)=&quot;updateTextBox(data[columnName])&quot;<br>       [ngClass]=&quot;{highlight:checkHighlight(i)}&quot;&gt;  <br>       {{data[columnName]}}<br>    &lt;/p&gt;<br> &lt;/div&gt;<br>&lt;/div&gt;</pre><p><strong>Explanation:</strong></p><p>Here I am trying to achieve the screen shown in image1.</p><ol><li>Input text box:</li></ol><p>Handling 2 way data binding with [ngModel] and (ngModelChange).</p><p>KeyUp event to search the list on a key stroke.</p><p>onfocus event to handle the on focus event when occured.</p><p>Onblur event to handle the focus is lost from the control.</p><p>2. Button :</p><p>Showing the drop-down symbol.</p><p>And handling on click event. When the onClick event is triggered the, the div containing the list will be shown.</p><p>3. A div that renders the list with each list item with a &lt;p&gt; tag.</p><p>To this &lt;p&gt; tag — (click) event to capture the selected item from the list and [ngClass] to highlight the current focused item.</p><p>Now move to the combo-box.component.ts file and the below code:</p><pre>import {Component, Input, OnInit} from &#39;@angular/core&#39;<br>import {BrowserModule} from &#39;@angular/platform-browser&#39;<br>import {FormsModule} from &#39;@angular/forms&#39;<br>import { ComboBoxPipe } from &#39;./combo-box.pipe&#39;;</pre><pre>export enum KEY_CODE {<br>UP_ARROW = 38,<br>DOWN_ARROW = 40,<br>TAB_KEY = 9<br>}</pre><pre>@Component({<br>selector: &#39;combo-box&#39;,<br>templateUrl: &#39;./combo-box.component.html&#39;,<br>styleUrls: [&#39;./combo-box.component.css&#39;],<br>providers: [ComboBoxPipe]<br>})<br>export class ComboBoxComponent implements OnInit {</pre><pre>@Input()<br>dataList: [];</pre><pre>@Input()<br>columnName: String;</pre><pre>dummyDataList: [];<br>showDropDown: boolean;<br>counter:number;</pre><pre>onFocusEventAction():void {<br>this.counter = -1;<br>}</pre><pre>onBlurEventAction(): void{<br>this.showDropDown = false;<br>}</pre><pre>onKeyDownAction(event: KeyboardEvent):void {<br>this.showDropDown = true;<br>if (event.keyCode === KEY_CODE.UP_ARROW) {<br>this.counter = (this.counter === 0)?this.counter:--this.counter;<br>this.checkHighlight(this.counter);<br>this.textToSort = this.dataList[this.counter][this.columnName];<br>}<br>if (event.keyCode === KEY_CODE.DOWN_ARROW) {<br>this.counter = (this.counter === this.dataList.length-1)?this.counter:++this.counter;<br>this.checkHighlight(this.counter);<br>this.textToSort = this.dataList[this.counter][this.columnName];<br>}<br>}</pre><pre>checkHighlight(currentItem):boolean{<br>if(this.counter === currentItem) return true;<br>else return false;<br>}</pre><pre>constructor(private ComboBoxPipe: ComboBoxPipe) {<br>this.reset();<br>}</pre><pre>ngOnInit(){<br>this.reset();<br>}</pre><pre>toogleDropDown():void {<br>this.showDropDown = !this.showDropDown;<br>}</pre><pre>reset(): void{<br>this.showDropDown = false;<br>this.dummyDataList = this.dataList;<br>   }</pre><pre>  textChange(value){<br>   this.dummyDataList = [];<br>   if(value.length &gt;0){<br>    this.dummyDataList = this.ComboBoxPipe.transform(this.dataList,         <br>                         this.columnName, value);<br>   if(this.dummyDataList){this.showDropDown = true;}<br>   } else {<br>     this.reset();<br>   }<br>  }<br>   updateTextBox(valueSelected){<br>     this.textToSort = valueSelected;<br>     this.showDropDown = false;<br>   }<br>}</pre><p>Lets design the component, I am using css only, just move to the combo-box.component.css file and paste the below:</p><pre>.combo-container {<br>position: fixed;<br>z-index: 9;<br>background: white;<br>}</pre><pre>.input-control{<br>width: 165px;<br>border: 0;<br>}</pre><pre>.data-container {<br>width: 196px;<br>background: white;<br>display: block;<br>position: relative;<br>border: 1px solid grey;<br>height: 200px;<br>overflow-y: scroll;<br>top: -1px;<br>}</pre><pre>.data-list {<br>cursor: pointer;<br>margin-top: 2px;<br>margin-bottom: 2px;<br>}</pre><pre>.drop-down {<br>border: 1px solid grey;<br>width: 196px;<br>}</pre><pre>.drop-down-button {<br>border: 0;<br>background: white;<br>}</pre><pre>.highlight{<br>background: grey;<br>}</pre><p>Now we are done with designing the component, lets see how to use it .</p><p>Go to the app.component.html file and call the component:</p><pre>&lt;combo-box<br>[dataList] = &quot;dataList&quot;<br>[columnName] = &quot;&#39;name&#39;&quot;<br>&gt;&lt;/combo-box&gt;</pre><p>If you observe the component there were 2 input data items we are passing to the combo-box, they are [dataList] and [columnName].</p><p>[dataList] -&gt; is an array of data.</p><p>[columnName] -&gt; Name of the property in a object in the above array so that we can show the list of values that are available for that property in all objects of the array.</p><p>And now, move to the app.component.ts file and add the following code:</p><pre>import { Component } from &#39;<a href="http://twitter.com/angular/core">@angular/core</a>&#39;;<br>import { BrowserModule } from &#39;<a href="http://twitter.com/angular/platform-browser">@angular/platform-browser</a>&#39;;<br>import { FormsModule } from &#39;<a href="http://twitter.com/angular/forms">@angular/forms</a>&#39;;<br>import { ComboBoxComponent } from &#39;./combo-box/combo-box.component&#39;;<br>import { ComboBoxPipe } from &#39;./combo-box/combo-box.pipe&#39;;</pre><pre><a href="http://twitter.com/Component">@Component</a>({<br>  selector: &#39;my-app&#39;,<br>  templateUrl: &#39;./app.component.html&#39;,<br>  styleUrls: [&#39;./app.component.css&#39;]<br>})<br>export class AppComponent {<br>  dataList: [];<br>  dummyDataList: [];<br>  showDropDown: boolean;</pre><pre>constructor() {<br>    this.dataList = [<br>      { &quot;name&quot;: &quot;Afghanistan&quot;, &quot;code&quot;: &quot;AF&quot; },<br>      { &quot;name&quot;: &quot;Åland Islands&quot;, &quot;code&quot;: &quot;AX&quot; },<br>      { &quot;name&quot;: &quot;Albania&quot;, &quot;code&quot;: &quot;AL&quot; },<br>      { &quot;name&quot;: &quot;Algeria&quot;, &quot;code&quot;: &quot;DZ&quot; },<br>      { &quot;name&quot;: &quot;American Samoa&quot;, &quot;code&quot;: &quot;AS&quot; },<br>      { &quot;name&quot;: &quot;AndorrA&quot;, &quot;code&quot;: &quot;AD&quot; },<br>      { &quot;name&quot;: &quot;Angola&quot;, &quot;code&quot;: &quot;AO&quot; },<br>      { &quot;name&quot;: &quot;Anguilla&quot;, &quot;code&quot;: &quot;AI&quot; },<br>      { &quot;name&quot;: &quot;Antarctica&quot;, &quot;code&quot;: &quot;AQ&quot; },<br>      { &quot;name&quot;: &quot;Antigua and Barbuda&quot;, &quot;code&quot;: &quot;AG&quot; }<br>    ];<br>  }<br>}</pre><p>We can make use of this combo-box component across the project.</p><p>Here is the live demo:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstackblitz.com%2Fedit%2Fangular6-combo-box%3Fembed%3D1&amp;url=https%3A%2F%2Fstackblitz.com%2Fedit%2Fangular6-combo-box&amp;image=https%3A%2F%2Fc.staticblitz.com%2Fassets%2Ficon-664493542621427cc8adae5e8f50d632f87aaa6ea1ce5b01e9a3d05b57940a9f.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=stackblitz" width="745" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8f6104d7af8f3c66f1924a03206b5a3/href">https://medium.com/media/b8f6104d7af8f3c66f1924a03206b5a3/href</a></iframe><p>Happy coding !!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b2eec03bece" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Deep dive into methods available on Objects In javascript]]></title>
            <link>https://medium.com/@madhavmahesh/a-deep-dive-into-methods-available-on-objects-in-javascript-bdfd56359ea?source=rss-4ceccb7a9200------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdfd56359ea</guid>
            <category><![CDATA[handlingobject]]></category>
            <category><![CDATA[oojs]]></category>
            <category><![CDATA[objects]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[methods]]></category>
            <dc:creator><![CDATA[Madhava Kumar Ippili]]></dc:creator>
            <pubDate>Mon, 28 May 2018 09:52:23 GMT</pubDate>
            <atom:updated>2018-05-31T08:14:19.111Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-8LXGJf9mUy117SPHKGrhw.jpeg" /></figure><p>With all the advanced JavaScript frameworks, we will be keep using the JSON to parse the data,<br>transform the JSON of one form to another form,<br>prepare a payload for a post request,<br>read the data from a get request and so many cases/instances.</p><p>For all these scenario’s we will be using the OOJS(Object Oriented JavaScript). Here OOJS is a part in JavaScript that helps us to deal the whole concept with an object kind of view and it supports some methods to act upon those objects.</p><p>Here I have listed some methods that we actually use which working with the objects:</p><p>Getting on the track……,</p><ol><li><a href="https://medium.com/p/bdfd56359ea#c6c0">Object.assign()</a></li></ol><p>2. Object.create()</p><p>3. Object.entries()</p><p>4. Object.freeze()</p><p>5. Object.seal()</p><p>6. Object.keys()</p><p>7. Object.values()</p><p>8. Object.defineProperty()</p><p>9. Object.defineProperties()</p><p>10. Object.preventExtensions()</p><p>Lets discuss each one of them.</p><ol><li><strong>Object.assign():</strong></li></ol><p>Object.assign() helps to copy the enumerable properties of one or more objects to a target object.</p><p><strong>Syntax:</strong></p><pre>Object.assign(target, ...sources)</pre><p><strong>Example:</strong></p><pre>const sourceObject = {<br>      property1:&quot;value1&quot;,<br>      property2:&quot;value2&quot;<br>};</pre><pre>const targetObject = Object.assign(sourceObject);</pre><p>Live demo here. <a href="https://jsfiddle.net/MadhavaIppili/sappuysk/">Object.assign demo</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjsfiddle.net%2FMadhavaIppili%2Fsappuysk%2Fembedded%2F&amp;url=https%3A%2F%2Fjsfiddle.net%2FMadhavaIppili%2Fsappuysk%2F&amp;image=https%3A%2F%2Fwww.gravatar.com%2Favatar%2Fdd3be070400c5112cf7b014f0b46f01e%2F%3Fdefault%3D%26s%3D120&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=jsfiddle" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe136bbceaebbf772837141032131c5f/href">https://medium.com/media/fe136bbceaebbf772837141032131c5f/href</a></iframe><p>2. <strong>Object.create():</strong></p><p>This method helps in creating a new object with the help of exiting objects or a new one.</p><p><strong>Syntax:</strong></p><pre>Object.create(proto[, propertiesObject])</pre><p><strong>Example:</strong></p><pre>const simpleObject = {<br>      property1: &#39;value 1&#39;,<br>      property2: &#39;value 2&#39;<br>};</pre><pre>const newObject = Object.create(simpleObject);</pre><p>Live demo of <a href="https://jsfiddle.net/MadhavaIppili/h19q8rue/">Object.create()</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjsfiddle.net%2FMadhavaIppili%2Fqbq09bd3%2Fembedded%2F&amp;url=https%3A%2F%2Fjsfiddle.net%2FMadhavaIppili%2Fqbq09bd3%2F&amp;image=https%3A%2F%2Fwww.gravatar.com%2Favatar%2Fdd3be070400c5112cf7b014f0b46f01e%2F%3Fdefault%3D%26s%3D120&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=jsfiddle" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/9efc8e52766dbf3c768eac08abcd7322/href">https://medium.com/media/9efc8e52766dbf3c768eac08abcd7322/href</a></iframe><p><strong>3. Object.entries()</strong></p><p>This method returns the objects own enumerable properties [‘key’,’value’] pairs in an array.</p><p><strong>Syntax:</strong></p><pre>Object.entries(obj)</pre><p><strong>Example:</strong></p><pre>const simpleObject = {<br>      property1: &#39;value 1&#39;,<br>      property2: &#39;value 2&#39;<br>};</pre><pre>const newObject = Object.entries(simpleObject);</pre><p>Live demo of <a href="https://jsfiddle.net/MadhavaIppili/qbq09bd3/">Object.entries()</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjsfiddle.net%2FMadhavaIppili%2Fqbq09bd3%2Fembedded%2F&amp;url=https%3A%2F%2Fjsfiddle.net%2FMadhavaIppili%2Fqbq09bd3%2F&amp;image=https%3A%2F%2Fwww.gravatar.com%2Favatar%2Fdd3be070400c5112cf7b014f0b46f01e%2F%3Fdefault%3D%26s%3D120&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=jsfiddle" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/9efc8e52766dbf3c768eac08abcd7322/href">https://medium.com/media/9efc8e52766dbf3c768eac08abcd7322/href</a></iframe><p><strong>4. Object.freeze()</strong></p><p>This method helps in freezing the object such as prevents adding new properties to the object, modifying the existing properties.</p><p><strong>Syntax:</strong></p><pre>Object.freeze(obj)</pre><p><strong>Example:</strong></p><pre>const simpleObject = {<br>      property1: &#39;value 1&#39;,<br>      property2: &#39;value 2&#39;<br>};</pre><pre>const newObject = Object.create(simpleObject);</pre><pre>document.getElementById(&#39;app&#39;).innerHTML = &#39;Before modification: &#39; + <br>newObject.property1;</pre><pre>newObject.property1 = &#39;new value&#39;;</pre><pre>document.getElementById(&#39;app&#39;).innerHTML += &#39;&lt;br/&gt;&lt;br/&gt;After Modification:&#39; + newObject.property1;</pre><pre>Object.freeze(newObject);<br>newObject.property1 = &#39;new value after freeze&#39;;</pre><pre>document.getElementById(&#39;app&#39;).innerHTML += &#39;&lt;br/&gt;&lt;br/&gt;Modification after freze:&#39; + newObject.property1;</pre><p>Live demo of <a href="https://jsfiddle.net/MadhavaIppili/ygy77kmb/">Object.freeze()</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjsfiddle.net%2FMadhavaIppili%2Fygy77kmb%2Fembedded%2F&amp;url=https%3A%2F%2Fjsfiddle.net%2FMadhavaIppili%2Fygy77kmb%2F&amp;image=https%3A%2F%2Fwww.gravatar.com%2Favatar%2Fdd3be070400c5112cf7b014f0b46f01e%2F%3Fdefault%3D%26s%3D120&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=jsfiddle" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce8971f7e61ddb28b66267976309b341/href">https://medium.com/media/ce8971f7e61ddb28b66267976309b341/href</a></iframe><p><strong>5. Object.seal()</strong></p><p>Similar to Object.freeze(), but here we can change the values of existing properties as long as they are writable.</p><p><strong>Syntax:</strong></p><pre>Object.seal(obj)</pre><p><strong>Example:</strong></p><pre>const simpleObject = {<br>      property1: &#39;value 1&#39;,<br>      property2: &#39;value 2&#39;<br>};</pre><pre>const newObject = Object.create(simpleObject);</pre><pre>document.getElementById(&#39;app&#39;).innerHTML = &#39;Before modification: &#39; + newObject.property1;</pre><pre>newObject.property1 = &#39;new value&#39;;</pre><pre>document.getElementById(&#39;app&#39;).innerHTML += &#39;&lt;br/&gt;&lt;br/&gt;After Modification:&#39; + newObject.property1;</pre><pre>Object.seal(newObject);</pre><pre>newObject.property1 = &#39;new value after seal&#39;;<br>document.getElementById(&#39;app&#39;).innerHTML += &#39;&lt;br/&gt;&lt;br/&gt;Modification after seal:&#39; + newObject.property1;</pre><pre>newObject.property3 = &#39;Property 3 added&#39;;</pre><pre>document.getElementById(&#39;app&#39;).innerHTML += &#39;&lt;br/&gt;&lt;br/&gt;Adding a new property after sealing the object:&#39; + newObject.property3;</pre><p>Live demo of <a href="https://jsfiddle.net/MadhavaIppili/dkv5c8db/">object.seal()</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjsfiddle.net%2FMadhavaIppili%2Fdkv5c8db%2Fembedded%2F&amp;url=https%3A%2F%2Fjsfiddle.net%2FMadhavaIppili%2Fdkv5c8db%2F&amp;image=https%3A%2F%2Fwww.gravatar.com%2Favatar%2Fdd3be070400c5112cf7b014f0b46f01e%2F%3Fdefault%3D%26s%3D120&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=jsfiddle" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ac8a96a33b63da1c22db636bf8732f5/href">https://medium.com/media/9ac8a96a33b63da1c22db636bf8732f5/href</a></iframe><p><strong>6. Object.keys()</strong></p><p>This method returns the given objects property names in the same order as we get in a loop.</p><p><strong>Syntax:</strong></p><pre>Object.keys(obj)</pre><p><strong>Example:</strong></p><pre>const simpleObject = {<br>      property1: &#39;value 1&#39;,<br>      property2: &#39;value 2&#39;<br>};</pre><pre>const keys = Object.keys(simpleObject);<br>document.getElementById(&#39;app&#39;).innerHTML = &#39;Keys of simple object: &#39; + keys;</pre><p>Live demo of <a href="https://jsfiddle.net/MadhavaIppili/utzw59ha/">Object.keys()</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjsfiddle.net%2FMadhavaIppili%2Futzw59ha%2Fembedded%2F&amp;url=https%3A%2F%2Fjsfiddle.net%2FMadhavaIppili%2Futzw59ha%2F&amp;image=https%3A%2F%2Fwww.gravatar.com%2Favatar%2Fdd3be070400c5112cf7b014f0b46f01e%2F%3Fdefault%3D%26s%3D120&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=jsfiddle" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/336e20d88dd54d972cb037188004ddfc/href">https://medium.com/media/336e20d88dd54d972cb037188004ddfc/href</a></iframe><p><strong>7. Object.values()</strong></p><p>This method returns an array of a given object&#39;s own enumerable property values, in the same order as that provided by a for.. in loop</p><p><strong>Syntax:</strong></p><pre>Object.values(obj)</pre><p><strong>Example:</strong></p><pre>const simpleObject = {<br>      property1: &#39;value 1&#39;,<br>      property2: &#39;value 2&#39;<br>};</pre><pre>document.getElementById(&#39;app&#39;).innerHTML = &#39;List of values in a object:  &#39; + Object.values(simpleObject);</pre><p>Live demo of <a href="https://jsfiddle.net/MadhavaIppili/exaLjLg0/">object.vlaues()</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjsfiddle.net%2FMadhavaIppili%2FexaLjLg0%2Fembedded%2F&amp;url=https%3A%2F%2Fjsfiddle.net%2FMadhavaIppili%2FexaLjLg0%2F&amp;image=https%3A%2F%2Fwww.gravatar.com%2Favatar%2Fdd3be070400c5112cf7b014f0b46f01e%2F%3Fdefault%3D%26s%3D120&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=jsfiddle" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/56e4eb4d3b61c515d1ef776ceb5eec2b/href">https://medium.com/media/56e4eb4d3b61c515d1ef776ceb5eec2b/href</a></iframe><p><strong>8. Object.defineProperty()</strong></p><p>Its a static method, which will help to create a property/modify an existing property and returns the object.</p><p><strong>Syntax:</strong></p><pre>Object.defineProperty(obj, prop, descriptor)</pre><p><strong>Example:</strong></p><pre>const simpleObject = {<br>      property1: &#39;value 1&#39;,<br>      property2: &#39;value 2&#39;<br>};<br>Object.defineProperty(simpleObject, &#39;property3&#39;, {<br>  value: &#39;hello&#39;,<br>  writable: false<br>});</pre><pre>simpleObject.property3 = &#39;hellllooooooooo&#39;;</pre><pre>document.getElementById(&#39;app&#39;).innerHTML = &#39;List of values in a object:  &#39; + simpleObject.property3;</pre><p>Live Demo of <a href="https://jsfiddle.net/MadhavaIppili/dp1f3nn4/">Object.defineProperty()</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjsfiddle.net%2FMadhavaIppili%2Fdp1f3nn4%2Fembedded%2F&amp;url=https%3A%2F%2Fjsfiddle.net%2FMadhavaIppili%2Fdp1f3nn4%2F&amp;image=https%3A%2F%2Fwww.gravatar.com%2Favatar%2Fdd3be070400c5112cf7b014f0b46f01e%2F%3Fdefault%3D%26s%3D120&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=jsfiddle" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/e56b8ea01cf45110ca0bb0240605f771/href">https://medium.com/media/e56b8ea01cf45110ca0bb0240605f771/href</a></iframe><p><strong>9. Object.defineProperties()</strong></p><p>This method defines new or modifies existing elements directly on the object.</p><p><strong>Syntax:</strong></p><pre>Object.defineProperties(obj, props)</pre><p><strong>Example:</strong></p><pre>const simpleObject = {<br>      property1: &#39;value 1&#39;,<br>      property2: &#39;value 2&#39;<br>};<br>Object.defineProperties(simpleObject, {&#39;property3&#39;: {<br>  value: &#39;hello&#39;,<br>  writable: false<br>},<br> &#39;property4&#39;:{<br>  value: &#39;hello its property 4&#39;,<br>  writable: false<br>}});</pre><pre>document.getElementById(&#39;app&#39;).innerHTML = &#39;List of values in a object:  &#39; + simpleObject.property4;</pre><p>Live demo of <a href="https://jsfiddle.net/MadhavaIppili/Lufqctth/">Object.defineProperties()</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjsfiddle.net%2FMadhavaIppili%2FLufqctth%2Fembedded%2F&amp;url=https%3A%2F%2Fjsfiddle.net%2FMadhavaIppili%2FLufqctth%2F&amp;image=https%3A%2F%2Fwww.gravatar.com%2Favatar%2Fdd3be070400c5112cf7b014f0b46f01e%2F%3Fdefault%3D%26s%3D120&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=jsfiddle" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/044c4363cadd4a5c02624330a52343dd/href">https://medium.com/media/044c4363cadd4a5c02624330a52343dd/href</a></iframe><p><strong>10. Object.preventExtensions()</strong></p><p>This method prevents adding new properties being added to the Object.</p><p><strong>Syntax:</strong></p><pre>Object.preventExtensions(obj)</pre><p><strong>Example:</strong></p><pre>const simpleObject = {<br>      property1: &#39;value 1&#39;,<br>      property2: &#39;value 2&#39;<br>};<br>Object.preventExtensions(simpleObject);<br>Object.defineProperties(simpleObject, {&#39;property3&#39;: {<br>  value: &#39;hello&#39;,<br>  writable: false<br>},<br> &#39;property4&#39;:{<br>  value: &#39;hello its property 4&#39;,<br>  writable: false<br>}});</pre><pre>document.getElementById(&#39;app&#39;).innerHTML = &#39;List of values in a object:  &#39; + simpleObject.property4;</pre><p>After running the above script, if you check the console window of your browser, you can see the below error.</p><p><em>TypeError: can’t define property “property3”: Object is not extensible</em></p><p>Live demo of <a href="https://jsfiddle.net/MadhavaIppili/y0ag1ps9/">Object.PreventExtensions()</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjsfiddle.net%2FMadhavaIppili%2Fy0ag1ps9%2Fembedded%2F&amp;url=https%3A%2F%2Fjsfiddle.net%2FMadhavaIppili%2Fy0ag1ps9%2F&amp;image=https%3A%2F%2Fwww.gravatar.com%2Favatar%2Fdd3be070400c5112cf7b014f0b46f01e%2F%3Fdefault%3D%26s%3D120&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=jsfiddle" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb08183be1e6be48f3e453af0c010034/href">https://medium.com/media/fb08183be1e6be48f3e453af0c010034/href</a></iframe><p><strong>Summary:</strong></p><p>These are some of the methods that are available from the Javascript Object. These methods will help to improve the handling of Objects more carefully and helps in achieving the OOJS writing.</p><p>Happy coding!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdfd56359ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a decorator]]></title>
            <link>https://medium.com/@madhavmahesh/creating-a-decorator-d5471edc69f3?source=rss-4ceccb7a9200------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5471edc69f3</guid>
            <category><![CDATA[decorators]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Madhava Kumar Ippili]]></dc:creator>
            <pubDate>Fri, 25 May 2018 09:54:47 GMT</pubDate>
            <atom:updated>2018-05-25T09:54:47.286Z</atom:updated>
            <content:encoded><![CDATA[<p>Shocked!!! Yes we can create a decorator. Lets understand what is a decorator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*761Bv2k1lXY6edvkhGYgdQ.jpeg" /></figure><blockquote>Decorator is a function</blockquote><p>Yes, decorator is a function. Here you can check the link <a href="http://www.typescriptlang.org/docs/handbook/decorators.html">Typescript Decorators</a>.</p><p>A decorator is basically a kind of declaring a annotation to a class, method, property, accessor, or parameter. A decorator will help to deliver the intent of its predecessor type. Means, when there is a decorator for a class, it will try to deliver the intent of the class.</p><p>Simple example we can take the usage of @Component decorator in Angular which will deliver the intent like, its component name, template, styles.</p><p>Currently decorator is available in experimental feature, we can make use of this in the below ways:</p><ol><li><strong>Command Line</strong>:</li></ol><pre>tsc --target ES5 --experimentalDecorators</pre><p>2. <strong>tsconfig.json</strong>:</p><pre>{<br>    &quot;compilerOptions&quot;: {<br>        &quot;target&quot;: &quot;ES5&quot;,<br>        &quot;experimentalDecorators&quot;: true<br>    }<br>}</pre><p>Remembered somethings like, how are we using decorators in angular. Yes angular guys also using the decorator feature in the above said second way. The below image shows the tsconfig.json file from the angular-cli generated project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*FbL6CDRsgY0KzOXQfY53bQ.png" /></figure><p>Look at line number 10.</p><p>A basic example:</p><p>Lets create a basic decorator that will print the decorator input.</p><pre>function Println(data) {<br>  console.log(data);<br>}</pre><pre><a href="http://twitter.com/Println">@Println</a>(&#39;Print from decorator&#39;)<br>class DecoratorExample {<br> constructor() {<br>  }<br>}</pre><pre>Output: Print from decorator</pre><p>You can check the live demo here: <a href="https://jsfiddle.net/MadhavaIppili/xbq8o5f2/">Demo</a></p><p>Looks interesting!!! Lets work on another basic example of printing the Decorator metadata:</p><pre>function Println(message) {<br>  console.log(&#39;Message&#39;, message.element1);<br>}</pre><pre><a href="http://twitter.com/Println">@Println</a>({<br>&#39;element1&#39;: &#39;Element1 Data&#39;<br>})<br>class DecoratorDemo {<br> constructor() {<br>  }<br>}</pre><p>You can check the live demo here: <a href="https://jsfiddle.net/MadhavaIppili/ogaqgLzt/">Demo</a></p><p>Lets look at the types of decorator available:</p><ol><li>class decorators,</li><li>method decorators,</li><li>property decorators,</li><li>accessor decorators, and</li><li>parameter decorators</li></ol><p><strong>Class decorators:</strong></p><p>Class decorators are applied for the class. These are placed just before the class declaration . The class decorators are applied to the constructor of the class and can be used to observer, modify or replace a class definition.</p><p><strong>Example:</strong></p><pre>function Println(data) {<br>  console.log(data);<br>}</pre><pre><a href="http://twitter.com/Println">@Println</a>(&#39;Print from decorator&#39;)<br>class DecoratorExample {<br> constructor() {<br>  }<br>}</pre><pre>Output: Print from decorator</pre><p><strong>Method Decorator:</strong></p><p>A method decorator is declared just before the method declaration. It is applied to the property descriptor of the method.And it can be used to observe, modify or replace a method definition.</p><pre>//In HTML file<br>&lt;div id=&quot;app&quot;&gt;&lt;/div&gt;</pre><pre>//In JS file<br>function Println(message) {<br>  console.log(&#39;Message&#39;, message.element1);<br>  document.querySelector(&quot;#app&quot;).innerHTML = message.element1;<br>}</pre><pre>class DecoratorDemo {<br>  <a href="http://twitter.com/Println">@Println</a>({<br>  &#39;element1&#39;: &#39;Element1 Data&#39;<br> })<br>  sampleMethod(){ }<br>}</pre><p><strong>Property Decorator:</strong></p><p>A property decorator is just declared before a property declaration.</p><pre>function Println(message) {<br>  console.log(&#39;Message&#39;, message.element1);<br>  document.querySelector(&quot;#app&quot;).innerHTML = message.element1;<br>}</pre><pre>class DecoratorDemo {<br>  <a href="http://twitter.com/Println">@Println</a>({<br>  &#39;element1&#39;: &#39;Element2 Data&#39;<br> })<br>  sampleProperty: any;<br>  <br>  sampleMethod(){ }<br>}</pre><p>Take a look at the live <a href="https://jsfiddle.net/MadhavaIppili/dmwo8fww/">demo</a>.</p><p><strong>Accessor decorator:</strong></p><p>An <em>Accessor Decorator</em> is declared just before an accessor declaration. The accessor decorator is applied to the <em>Property Descriptor</em> for the accessor and can be used to observe, modify, or replace an accessor’s definitions.</p><p><strong>Parameter Decorators:</strong></p><p><em>Parameter Decorator</em> is declared just before a parameter declaration. The parameter decorator is applied to the function for a class constructor or method declaration.</p><p><strong>Property Decorators:</strong></p><p>A <em>Property Decorator</em> is declared just before a property declaration. A property decorator cannot be used in a declaration file, or in any other ambient context (such as in a declare class).</p><p><strong>Summary:</strong></p><p>Decorators are kind of new functionality that came from Typescript which helps us in maintaining a nice and minimal coding.</p><p>If we are using Angular, there were some inbuilt Decorators that are already available. If there comes a chance to work with tyepsscript in place of Javascript In your webapp, I would really suggest to try making use of Decorators.</p><p>Happy coding!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5471edc69f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exporting an Excel file in Angular]]></title>
            <link>https://medium.com/@madhavmahesh/exporting-an-excel-file-in-angular-927756ac9857?source=rss-4ceccb7a9200------2</link>
            <guid isPermaLink="false">https://medium.com/p/927756ac9857</guid>
            <category><![CDATA[excel]]></category>
            <category><![CDATA[angular-cli]]></category>
            <category><![CDATA[angular-6]]></category>
            <category><![CDATA[export]]></category>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Madhava Kumar Ippili]]></dc:creator>
            <pubDate>Wed, 23 May 2018 13:51:48 GMT</pubDate>
            <atom:updated>2018-05-25T03:31:47.529Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*FuO27XVXAfbKnXmvYXu6uA.jpeg" /></figure><p>Hi all, this time I came up with a feature to implement the exporting an Excel file in our web apps built with Angular. This is one of the frequently used feature in our web apps. There are different exporting features that we try to achieve like, exporting a<br> doc files like .doc, .docx, <br>spreasheats like .xls, .xlsx, .csv<br>pdf files and also some image files.</p><p>Today I will show you the way to export a xlsx file from angular6.</p><p>Environment setup:</p><ol><li>Node version 8.</li><li>Angular CLI 6.</li><li>Angular core updated to Angular 6.</li><li>file-saver npm module,</li><li>xlsx npm module.</li></ol><p>File-saver module will help to export a file.<br>xlsx module will help to create a .xlsx file with required data and filename.So combining these 2, after giving the data as input to xlsx module it will convert the given array data to excel view and assigns the name that we passed to it.</p><p>Here the xlsx module will make prepare the required workbook, sheet and sets the data in a tabular manner with in the cells.</p><p>Getting on the track:</p><ol><li>Prepare a new angular project with Angular CLI with the below command:</li></ol><p>ng new angular-file-exporter-demo</p><p>2. Once the project gets created and the npm install is successfull.Run the below commands:</p><p>npm install file-saver — save</p><p>npm install xlsx — save</p><p>3. Now move to the app directory and create a directory called services / sharedServices. Its up to you to use any one, I will go with services.<br>With in this directory generate a service file with the below command:<br>ng g service excel</p><p>And copy paste the below code:</p><pre>import { Injectable } from &#39;@angular/core&#39;;<br>import * as FileSaver from &#39;file-saver&#39;;<br>import * as XLSX from &#39;xlsx&#39;;</pre><pre>const EXCEL_TYPE = &#39;application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8&#39;;</pre><pre>const EXCEL_EXTENSION = &#39;.xlsx&#39;;</pre><pre>@Injectable()<br>export class ExcelService {<br>constructor() { }<br>public exportAsExcelFile(json: any[], excelFileName: string): void {</pre><pre>  const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(json);</pre><pre>  const workbook: XLSX.WorkBook = { Sheets: { &#39;data&#39;: worksheet }, SheetNames: [&#39;data&#39;] };</pre><pre>  const excelBuffer: any = XLSX.write(workbook, { bookType: &#39;xlsx&#39;, type: &#39;array&#39; });</pre><pre>  this.saveAsExcelFile(excelBuffer, excelFileName);<br>}</pre><pre>private saveAsExcelFile(buffer: any, fileName: string): void {<br>   const data: Blob = new Blob([buffer], {type: EXCEL_TYPE});</pre><pre>   FileSaver.saveAs(data, fileName + &#39;_export_&#39; + new  Date().getTime() + EXCEL_EXTENSION);<br>}<br>}</pre><p>4. Now move to the app.component.ts file and add the below code:</p><pre>import { Component } from &#39;@angular/core&#39;;<br>import {ExcelService} from &#39;./services/excel.service&#39;;</pre><pre>@Component({<br>selector: &#39;my-app&#39;,<br>templateUrl: &#39;./app.component.html&#39;,<br>styleUrls: [&#39;./app.component.css&#39;]<br>})<br>export class AppComponent {<br>data: any = [{<br>eid: &#39;e101&#39;,<br>ename: &#39;ravi&#39;,<br>esal: 1000<br>},{<br>eid: &#39;e102&#39;,<br>ename: &#39;ram&#39;,<br>esal: 2000<br>},{<br>eid: &#39;e103&#39;,<br>ename: &#39;rajesh&#39;,<br>esal: 3000<br>}];</pre><pre>constructor(private excelService:ExcelService){<br>}</pre><pre>exportAsXLSX():void {<br>   this.excelService.exportAsExcelFile(this.data, &#39;sample&#39;);<br>}<br>}</pre><p>Now we are done with creating a service and accessing it in out component, lets do the necessary changes in app.component.html to show the json data in a table and the export button.</p><p>5. Open the app.component.html and save the below code:</p><pre>&lt;p&gt;Exporting an excel file of type .xslx !!!&lt;/p&gt;</pre><pre>&lt;p&gt;Export as XLSX by clicking the below button&lt;/p&gt;</pre><pre>&lt;button (click)=&quot;exportAsXLSX()&quot;&gt;&lt;i class=&quot;fa fa-file-excel-o&quot; style=&quot;font-size:48px;color:blue&quot;&gt;&lt;/i&gt;&lt;/button&gt;</pre><pre>&lt;table&gt;<br> &lt;tr&gt;<br>   &lt;td&gt;Eid&lt;/td&gt;<br>   &lt;td&gt;Ename&lt;/td&gt;<br>   &lt;td&gt;Esal&lt;/td&gt;<br> &lt;/tr&gt;<br> &lt;tr *ngFor=&quot;let item of data&quot;&gt;<br>   &lt;td&gt;{{item.eid}}&lt;/td&gt;<br>   &lt;td&gt;{{item.ename}}&lt;/td&gt;<br>   &lt;td&gt;{{item.esal}}&lt;/td&gt;<br> &lt;/tr&gt;<br>&lt;/table&gt;</pre><p>6. And also as a final step to show a icon on the export button, add the cdn path of font-awesome in the index.html file.<br>https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css</p><p>7. Now run the command ng serve and you go to localhost:4200 in the browser and you can see the below screen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*s4IKw4djx7U-CwL1L9P_7w.png" /></figure><p>8. Just click on the excel file icon available above the table and you see an excel file getting downloaded.</p><p>Here you can find the working demo</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fstackblitz.com%2Fedit%2Fangular6-export-xlsx%3Fembed%3D1&amp;url=https%3A%2F%2Fstackblitz.com%2Fedit%2Fangular6-export-xlsx%3Fembed%3D1&amp;image=https%3A%2F%2Fc.staticblitz.com%2Fassets%2Ficon-664493542621427cc8adae5e8f50d632f87aaa6ea1ce5b01e9a3d05b57940a9f.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=stackblitz" width="745" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/1dea36dc6a8b4e475760f37e99e46334/href">https://medium.com/media/1dea36dc6a8b4e475760f37e99e46334/href</a></iframe><p>Please drop comments with your suggestions.</p><p>Happy coding!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=927756ac9857" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Array methods in Javascript]]></title>
            <link>https://medium.com/@madhavmahesh/array-methods-in-javascript-757beced669b?source=rss-4ceccb7a9200------2</link>
            <guid isPermaLink="false">https://medium.com/p/757beced669b</guid>
            <category><![CDATA[fill]]></category>
            <category><![CDATA[maps]]></category>
            <category><![CDATA[filters]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reduce]]></category>
            <dc:creator><![CDATA[Madhava Kumar Ippili]]></dc:creator>
            <pubDate>Tue, 22 May 2018 07:58:59 GMT</pubDate>
            <atom:updated>2018-05-24T04:30:30.588Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*dktwKuIpboVSIKXaxBu0VQ.jpeg" /></figure><p>So many of us are pretty good at writing code in javascript. And I am also one of the person who loves to write coding in this.</p><p>Just want to share the view on some of the array methods with which we can make the coding little more simpler, cleaner, perfect.</p><p>I am going to discuss the methods of Array, which are actually existing to handle the code but we are not using them….,</p><p>Let me take a simple example like, for traversing across all the elements/ objects inside a array, we will go with forEach, yes its a suggested and correct way only. But, not suggested in all the cases.</p><p>forEach will actually executes a function for every element/object that exists in the array, but does not return or change the existing things in the array.</p><p>To handle situations like traversing across the array and returning somethings from the array based on a condition/ without any condition, we can make use of array.map() method.</p><p>Similarly there were some more methods that are available to make use of:</p><p>array.map();</p><p>array.some();</p><p>array.reduce();</p><p>array.filter();</p><p>array.fill();</p><p>Hope you all know about this, array.someMethod() means that someMethod() is the method tagged to Array datatype with the Prototype keyword. So that we can execute that someMethod on the data existing in the array directly with our logic.</p><h3>array.map():</h3><p>It creates a new array with the results of functions executed on the every element in the array.</p><p><strong>Syntax:</strong></p><pre>var new_array = arr.map(function callback(currentValue[, index[, array]]) {<br>    // Return element for new_array<br>}[, thisArg])</pre><p><strong>Code Snippet:</strong></p><p>var arrayData = [1, 2, 3, 4];<br>var resultArray = arrayData.map(function(element){<br> return element*2;<br>});</p><p><strong>Output:</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FmadhavApps%2Fembed%2Fpreview%2FGdeyYY%3Fheight%3D600%26slug-hash%3DGdeyYY%26default-tabs%3Djs%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io%26embed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2FmadhavApps%2Fpen%2FGdeyYY&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F1388533.GdeyYY.small.5f50ac53-dc80-4ed8-82a5-1fcbe5a6a074.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/65dee24361bb678e8f4ddf0a23475885/href">https://medium.com/media/65dee24361bb678e8f4ddf0a23475885/href</a></iframe><h3>array.some():</h3><p>This method helps in running a test across all the elements in the array.</p><p>Example scenarios of using this method:</p><p>Checking is there any employee whose salary is more than 5000 from the array.<br>Checking who got first in the class from the data available from the array</p><p><strong>Syntax:</strong></p><pre>arr.some(callback[, thisArg])</pre><p><strong>Code snippet:</strong></p><p>var arrayData = [1, 2, 3, 4];<br>var resultArray = arrayData.some(function(element){<br> return element&gt;3;<br>});</p><p><strong>Output:</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FmadhavApps%2Fembed%2Fpreview%2FWJmdKV%3Fheight%3D600%26slug-hash%3DWJmdKV%26default-tabs%3Djs%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io%26embed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2FmadhavApps%2Fpen%2FWJmdKV&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F1388533.WJmdKV.small.bff2a8c4-61ee-4893-a8f9-518cac05049f.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/30bbae413bb13bc84ce87b817c6f0d07/href">https://medium.com/media/30bbae413bb13bc84ce87b817c6f0d07/href</a></iframe><p><strong>array.reduce():</strong></p><p>array.reduce() applies a function to accumulate all the element from left to right to make a single element.</p><p><strong>syntax:</strong></p><pre>arr.reduce(callback[, initialValue])</pre><p><strong>Code snippet:</strong></p><p>var arrayData = [1, 2, 3, 4];<br>function reducer(sum, element){<br> return sum+element;<br>}<br>var resultArray = arrayData.reduce(reducer);</p><p><strong>Output:</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FmadhavApps%2Fembed%2Fpreview%2FMGxrMj%3Fheight%3D600%26slug-hash%3DMGxrMj%26default-tabs%3Djs%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io%26embed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2FmadhavApps%2Fpen%2FMGxrMj&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F1388533.MGxrMj.small.e9e82342-dfd9-4754-bb5e-f97cf0afbc00.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f8bf45204e0595f64ecd953060123d5/href">https://medium.com/media/7f8bf45204e0595f64ecd953060123d5/href</a></iframe><p><strong>array.filter():</strong></p><p>array.filter() helps to create a new array with all the elements that pass a test provided by the function.</p><p><strong>syntax:</strong></p><pre>var newArray = arr.filter(callback(element[, index[, array]])[, thisArg])</pre><p><strong>Code snippet:</strong></p><p>var arrayData = [1, 2, 3, 4];</p><p>var resultArray = arrayData.filter(function(element){<br> return element&gt;2;<br>});</p><p><strong>Output:</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FmadhavApps%2Fembed%2Fpreview%2FerXVNv%3Fheight%3D600%26slug-hash%3DerXVNv%26default-tabs%3Djs%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io%26embed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2FmadhavApps%2Fpen%2FerXVNv&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fm.cdpn.io%2Fscreenshot-coming-soon-small.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/db6f785df3b81d5471afa3e5578a00a6/href">https://medium.com/media/db6f785df3b81d5471afa3e5578a00a6/href</a></iframe><p><strong>array.fill():</strong></p><p>array.fill() method helps to fill a value provided the start and end index to the function.</p><p><strong>Syntax:</strong></p><pre>arr.fill(value[, start[, end]])</pre><p><strong>Code Snippet:</strong></p><p>var arrayData = [1, 2, 3, 4];<br>arrayData.fill(0,2,4);</p><p><strong>Output:</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FmadhavApps%2Fembed%2Fpreview%2Fyjwvag%3Fheight%3D600%26slug-hash%3Dyjwvag%26default-tabs%3Djs%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io%26embed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2FmadhavApps%2Fpen%2Fyjwvag&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fm.cdpn.io%2Fscreenshot-coming-soon-small.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b0c7f0af0f9b097db964542bc780227/href">https://medium.com/media/6b0c7f0af0f9b097db964542bc780227/href</a></iframe><p><strong>Summary:</strong></p><p>Using these inbuilt methods of array we can make the life easier, no need to take pains of writing, for..loops, forEach.., These are proven and suggested methods.</p><p>Happy coding!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=757beced669b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>