<?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"><channel><title><![CDATA[Untitled Publication]]></title><description><![CDATA[Untitled Publication]]></description><link>https://blog.mohitkumartoshniwal.com</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Apr 2026 02:42:44 GMT</lastBuildDate><atom:link href="https://blog.mohitkumartoshniwal.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Most used JavaScript methods I use in my day to day job]]></title><description><![CDATA[Introduction
This article is mainly about me walking you through some of the common JavaScript methods which I use in my day to day job. Its not an exhaustive list but covers a lot of methods which should be known I feel. I am not planning to explain...]]></description><link>https://blog.mohitkumartoshniwal.com/most-used-javascript-methods-i-use-in-my-day-to-day-job</link><guid isPermaLink="true">https://blog.mohitkumartoshniwal.com/most-used-javascript-methods-i-use-in-my-day-to-day-job</guid><category><![CDATA[array]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[array methods]]></category><category><![CDATA[web]]></category><dc:creator><![CDATA[Mohit Kumar Toshniwal]]></dc:creator><pubDate>Sun, 20 Nov 2022 16:22:41 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/unsplash/eYpcLDXHVb0/upload/v1668960530281/_L1-4Gy2o.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-introduction">Introduction</h1>
<p>This article is mainly about me walking you through some of the common JavaScript methods which I use in my day to day job. Its not an exhaustive list but covers a lot of methods which should be known I feel. I am not planning to explain all the methods deeply but would provide a cursory look for each method. Relevant links are provided for each method so you can further explore them in your free time.</p>
<p>So, lets start</p>
<h3 id="heading-arraymaphttpsdevelopermozillaorgen-usdocswebjavascriptreferenceglobalobjectsarraymap"><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map">Array.map</a></h3>
<p>I use map normally when I would like to convert an array of items(number, boolean, string,...) to some different representation. Let's take an example to understand it more clearly. </p>
<p>Suppose, you have been given an array of dates in ISO format and you would like to compare the dates with each other. I feel the easiest way would be to convert the dates to a number and compare those numbers instead.</p>
<pre><code><span class="hljs-keyword">let</span> dates=[<span class="hljs-string">'2022-11-20T14:09:36.865Z'</span>, <span class="hljs-string">'2022-10-19T14:09:36.865Z'</span>, <span class="hljs-string">'2022-09-20T14:07:36.865Z'</span>]
dates.map(<span class="hljs-function">(<span class="hljs-params">date</span>)=&gt;</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>(date).getTime()) <span class="hljs-comment">// [1668953376865, 1666188576865, 1663682856865]</span>
</code></pre><p>As a side note, the returned value of the map operation is a new array with the transformation provided by you.</p>
<h3 id="heading-arrayfilterhttpsdevelopermozillaorgen-usdocswebjavascriptreferenceglobalobjectsarrayfilter"><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter">Array.filter</a></h3>
<p>Let's check out now filter function. Personally, I feel filter function should have been renamed to filterOut😅. In the initial days of learning JavaScript, this was the only method which I had to look repeatedly online.</p>
<p>Anyways, filter will provide you a new array with items removed out of the array based on the condition you provide. A simple example would be</p>
<pre><code><span class="hljs-keyword">let</span> numbers=[<span class="hljs-number">2</span>, <span class="hljs-number">23</span>, <span class="hljs-number">33</span>, <span class="hljs-number">4</span>]
numbers.filter(<span class="hljs-function"><span class="hljs-params">number</span> =&gt;</span> number &gt; <span class="hljs-number">20</span> ) <span class="hljs-comment">// [23, 33]</span>
</code></pre><h3 id="heading-arrayreducehttpsdevelopermozillaorgen-usdocswebjavascriptreferenceglobalobjectsarrayreduce"><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce">Array.reduce</a></h3>
<p>Personally, I am okay with with writing more code instead of using reduce to make my code look compact. Its a personal preference, but if it makes sense that reduce is THE way to go for any specific problem, I don't shy away from using that as well. Enough with the monologue, I guess. So, what does reduce help us accomplish. Basically, the simplest answer is that you give it an array of items and it would return you a single value. The value can be anything based on the logic you provide.</p>
<pre><code><span class="hljs-keyword">const</span> array = [<span class="hljs-number">10</span>, <span class="hljs-number">22</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>];

<span class="hljs-comment">// 0 + 10 + 22 + 3 + 4</span>
<span class="hljs-keyword">const</span> initialValue = <span class="hljs-number">0</span>;
<span class="hljs-keyword">const</span> sum = array.reduce(
  <span class="hljs-function">(<span class="hljs-params">accumulator, currentValue</span>) =&gt;</span> accumulator + currentValue,
  initialValue
); <span class="hljs-comment">// 39</span>
</code></pre><h3 id="heading-arrayincludeshttpsdevelopermozillaorgen-usdocswebjavascriptreferenceglobalobjectsarrayincludes"><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes">Array.includes</a></h3>
<p>Instead of using <a target="_blank" href="Array.prototype.indexOf()">indexOf</a> and checking the result with specific numbers. My personal favourite of checking whether a value is present in the array is to use <em>includes</em> instead. It will return you a Boolean value based on whether the value is present in the array.</p>
<pre><code><span class="hljs-keyword">const</span> array = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>];
array.includes(<span class="hljs-number">2</span>) <span class="hljs-comment">// true</span>
</code></pre><p>The only caveat is that it is case sensitive. So, "mohit" and "Mohit" are not the same value in the  👀 of <em>includes</em>. So, maybe convert all your strings to lowercase before using <em>includes</em> on them.</p>
<h3 id="heading-stringsplithttpsdevelopermozillaorgen-usdocswebjavascriptreferenceglobalobjectsstringsplit"><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split">String.split</a></h3>
<p>Now, suppose if you have a requirement to convert a string to an array and would like to do further processing on it using the array methods which we already discussed above, then <em>split </em>is your buddy here. You would need to give it a separator on the basis of which, its going to split the string into an array of strings.</p>
<pre><code><span class="hljs-keyword">const</span> str = <span class="hljs-string">'The quick brown fox jumps over the lazy dog.'</span>;
<span class="hljs-keyword">const</span> words = str.split(<span class="hljs-string">' '</span>); <span class="hljs-comment">//  ["The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog."]</span>
</code></pre><h3 id="heading-arrayjoinhttpsdevelopermozillaorgen-usdocswebjavascriptreferenceglobalobjectsarrayjoin"><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join">Array.join</a></h3>
<p><em>join</em> is the opposite of <em>split </em>. It will convert an array of strings to a new string with the separator which you provide.</p>
<pre><code><span class="hljs-keyword">const</span> words=[<span class="hljs-string">"The"</span>, <span class="hljs-string">"quick"</span>, <span class="hljs-string">"brown"</span>, <span class="hljs-string">"fox"</span>, <span class="hljs-string">"jumps"</span>, <span class="hljs-string">"over"</span>, <span class="hljs-string">"the"</span>, <span class="hljs-string">"lazy"</span>, <span class="hljs-string">"dog."</span>]
words.join(<span class="hljs-string">' '</span>); <span class="hljs-comment">//  "The quick brown fox jumps over the lazy dog."</span>
</code></pre><h3 id="heading-arraysplicehttpsdevelopermozillaorgen-usdocswebjavascriptreferenceglobalobjectsarraysplice"><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice">Array.splice</a></h3>
<p>If you would like to modify an existing array. Then <em>splice</em> is the method which you are searching for. It would help you to add or remove element/elements from the array in-place. It would return elements which were removed from the array</p>
<pre><code><span class="hljs-keyword">const</span> months = [<span class="hljs-string">'Jan'</span>, <span class="hljs-string">'March'</span>, <span class="hljs-string">'April'</span>, <span class="hljs-string">'June'</span>];
<span class="hljs-keyword">const</span> removedItem = months.splice(<span class="hljs-number">1</span>, <span class="hljs-number">1</span>); 
<span class="hljs-built_in">console</span>.log(removedItem) <span class="hljs-comment">// ["March"]</span>
<span class="hljs-built_in">console</span>.log(months) <span class="hljs-comment">// ["Jan", "April", "June"]</span>
</code></pre><h3 id="heading-arrayslicehttpsdevelopermozillaorgen-usdocswebjavascriptreferenceglobalobjectsarrayslice"><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice">Array.slice</a></h3>
<p>Now, suppose you would like to have a copy (shallow) of a selected portion of the array or a new (shallow) copy of the whole array, then slice can be used for it.</p>
<pre><code><span class="hljs-keyword">const</span> animals = [<span class="hljs-string">'ant'</span>, <span class="hljs-string">'bison'</span>, <span class="hljs-string">'elephant'</span>];
animals.slice(<span class="hljs-number">2</span>) <span class="hljs-comment">// ["elephant"]</span>
</code></pre><h3 id="heading-arraysorthttpsdevelopermozillaorgen-usdocswebjavascriptreferenceglobalobjectsarraysort"><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort">Array.sort</a></h3>
<p>Now, suppose if you would like to arrange the items in an array in ascending or descending order, then we can use <em>sort</em> and provide the condition based on which the sorting will happen. The array will be sorted in-place. </p>
<pre><code><span class="hljs-keyword">const</span> array = [<span class="hljs-number">10</span>,<span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">22</span> ];
array.sort(<span class="hljs-function">(<span class="hljs-params"> a, b</span>)=&gt;</span> a-b); <span class="hljs-comment">// [3, 4, 10, 22]</span>
</code></pre><p>A word of caution, always make sure that your comparator function can return +ve value or -ve value or 0 based on your requirements. Basically, in the above example, I could have used a different comparator function, which might seem logical at first, but the sorting will not work on them and there are some other gotchas. If any confusion, I would highly suggest you to check out <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort">mdn</a></p>
<pre><code><span class="hljs-keyword">const</span> array = [<span class="hljs-number">10</span>,<span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">22</span> ];
array.sort(<span class="hljs-function">(<span class="hljs-params">a, b</span>) =&gt;</span> a &gt; b ? <span class="hljs-number">1</span> : <span class="hljs-number">0</span>); <span class="hljs-comment">// [10, 3, 4, 22]</span>
</code></pre><p>As mentioned in the start of the article, these are just some of the most common methods which  I use daily. There are a lot of other methods which you can further explore. To name a few, </p>
<ul>
<li><em>reverse</em></li>
<li><em>some</em></li>
<li><em>every</em></li>
<li><em>fill </em></li>
<li><em>find</em></li>
<li><em>push</em></li>
<li><em>pop </em>
and the list goes on.</li>
</ul>
<p>Happy Learning!!</p>
]]></content:encoded></item><item><title><![CDATA[i2djs for dummies]]></title><description><![CDATA[Disclaimer: This post is mainly intended for people who are somewhat familiar with web dev in general as well as integral components of web graphics like svg, canvas, etc.
For introduction, i2djs is a library which helps in rendering different kinds ...]]></description><link>https://blog.mohitkumartoshniwal.com/i2djs-for-dummies</link><guid isPermaLink="true">https://blog.mohitkumartoshniwal.com/i2djs-for-dummies</guid><category><![CDATA[D3.js]]></category><category><![CDATA[SVG]]></category><category><![CDATA[webdev]]></category><category><![CDATA[graphics]]></category><category><![CDATA[HTML Canvas]]></category><dc:creator><![CDATA[Mohit Kumar Toshniwal]]></dc:creator><pubDate>Tue, 24 May 2022 11:18:11 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1653390869128/OoB6i_9oV.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><em>Disclaimer: This post is mainly intended for people who are somewhat familiar with web dev in general as well as integral components of web graphics like svg, canvas, etc.</em></p>
<p>For introduction, i2djs is a library which helps in rendering different kinds of elements from svg, canvas and webgl land in your browser window. With the help of i2djs, it is very easy to switch between canvas, svg and webgl contexts. i2djs gives you native svg elements like rect, circle etc. for all the three different contexts. It also supports events and behaviours for all the three different contexts to create more interactive visualisations. </p>
<p>In this post, my main goal is to make you familiar about different methods available in i2djs through a simple example as well as show how easy it is to get started and maybe in my next post, I will try to make that same replica of whatever we do in canvas today both in svg and webgl as well.</p>
<p>So, let us get started. If you would like to see the final output, I would suggest you to checkout the <a target="_blank" href="https://codepen.io/MohitToshniwal/pen/yLvoaWJ?editors=0010">codepen</a>, otherwise follow along with me so that we can look into what i2djs has to offer.</p>
<p>First of all, we need to create a basic html page with some css sprinkled in it and point it to i2djs, you can just copy the below snippet</p>
<pre><code><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">"X-UA-Compatible"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"IE=edge"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>barchart<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">defer</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://i2djs.github.io/I2Djs/dist/i2d.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">defer</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"index.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
      *,
      *<span class="hljs-selector-pseudo">::after</span>,
      *<span class="hljs-selector-pseudo">::before</span> {
        <span class="hljs-attribute">margin</span>: <span class="hljs-number">0</span>;
        <span class="hljs-attribute">padding</span>: <span class="hljs-number">0</span>;
        <span class="hljs-attribute">font-family</span>: <span class="hljs-string">"Courier New"</span>, Courier, monospace;
      }
      <span class="hljs-selector-tag">html</span>,
      <span class="hljs-selector-tag">body</span> {
        <span class="hljs-attribute">height</span>: <span class="hljs-number">100%</span>;
        <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
      }
      <span class="hljs-selector-id">#myCanvas</span> {
        <span class="hljs-attribute">height</span>: <span class="hljs-number">100vh</span>;
        <span class="hljs-attribute">width</span>: <span class="hljs-number">100%</span>;
        <span class="hljs-attribute">background-color</span>: black;
      }
    </span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"myCanvas"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre><p>As you can see in the above snippet, I have added a script tag pointing to an index.js file where we will be adding our code related to i2djs and in html we have added a div with the <em>id</em> attribute as <strong>myCanvas</strong> where i2djs will attach a container like canvas in our case. Eventually, whatever we do will be rendered in that container element (canvas in our case).</p>
<p>So let us now create a canvas layer where our elements will reside. You might be thinking "why do we need a layer in the first place?". Well, the thing is that we can create different kinds of layer based on the use cases, we can put one layer on top of the other. We can combine multiple layers of different contexts to build composite scenes and the layers will be stacked in the order of their creation. i2djs at present provides three layers i.e <strong>canvasLayer</strong>, <strong>svgLayer</strong> and <strong>webglLayer</strong> which respectively represents <strong>canvas</strong>, <strong>svg</strong> and <strong>webgl</strong> semantics (duh). 
So, now just copy the below code and paste it in index.js file.</p>
<pre><code>let renderer <span class="hljs-operator">=</span> i2d.canvasLayer(<span class="hljs-string">"#myCanvas"</span>, {}, {});
</code></pre><p>So, what we are doing in the above code is that we are telling i2djs about the type of layer which we are gonna use as well as the containerId (<strong>#myCanvas</strong>) where we want the canvas to be rendered. </p>
<p>Similar to how d3.js works with data, i2djs also supports data binding for rendering graphical elements. So, let us first add some custom data, just copy and paste the below code in index.js file after renderer declaration.</p>
<pre><code><span class="hljs-string">let</span> <span class="hljs-string">data</span> <span class="hljs-string">=</span> [
  {
    <span class="hljs-attr">id:</span> <span class="hljs-number">1</span>,
    <span class="hljs-attr">value:</span> <span class="hljs-number">23</span>
  },
  {
    <span class="hljs-attr">id:</span> <span class="hljs-number">2</span>,
    <span class="hljs-attr">value:</span> <span class="hljs-number">30</span>
  },
  {
    <span class="hljs-attr">id:</span> <span class="hljs-number">3</span>,
    <span class="hljs-attr">value:</span> <span class="hljs-number">40</span>
  }
]<span class="hljs-string">;</span>
</code></pre><p>So now since we have the data, we can use that to create and interact with graphical element like circle in the canvas layer using data join actions (enter, exit and update) provided by i2djs. Before that we need to write some code which will help i2djs to uniquely identify a part of data and bind it to a graphical element. So, just copy and paste the below code after <strong>data</strong> declaration.</p>
<pre><code>let joinRef <span class="hljs-operator">=</span> renderer.join(data, <span class="hljs-string">"circle"</span>, {
  joinOn: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">d, i, n</span>) </span>{
    <span class="hljs-keyword">return</span> d.id;
  },
  action: {
    enter: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">data</span>) </span>{},
    exit: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">nodes</span>) </span>{},
    update: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">nodes</span>) </span>{}
  }
});
</code></pre><p>So, what we are doing in the above code is that we are telling i2djs about the data as well as the elements which needs to be bound with that data. In our case, <em>circle</em> element will be bound with the individual data elements (objects) and since i2djs needs a unique key to identify and bind data to the graphical element, so to indicate the uniqueness in our <strong>data</strong> in this example, we will be using <em>id</em> inside the <strong>joinOn</strong> function, to help i2djs do its magic. Along with that, we have added an action object which contains enter, exit and update functions. These functions helps us to render elements in the canvas. I will be explaining their use cases soon.</p>
<p>After seeing the black screen for so long, finally let us add some circles. Copy the below code and paste it inside the enter function. </p>
<pre><code>      <span class="hljs-built_in">this</span>.createEls(data.circle, {
        el: <span class="hljs-string">"circle"</span>,
        attr: {
          cx: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">d</span>) </span>{
            <span class="hljs-keyword">return</span> d.id <span class="hljs-operator">*</span> <span class="hljs-number">100</span>;
          },
          cy: renderer.height <span class="hljs-operator">/</span> <span class="hljs-number">2</span>,
          r: <span class="hljs-number">20</span>
        },
        style: {
          fillStyle: <span class="hljs-string">"orange"</span>
        }
      });
</code></pre><p>Hopefully, at present, you will be able to see some orange circles in your screen. As a short explanation, we are creating circle elements based on the data that we have specified earlier. We are calculating individual circle's attributes as well as giving it some styles inside the enter function.</p>
<p>I feel that the code is somewhat intuitive and I would suggest you to tinker the code by modifying the attributes and styles of the circle and see how it affects the output in the browser.</p>
<p>Now, just trust me and modify the update and exit functions with the below code. I will show their usecase soon.</p>
<pre><code>    exit: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">nodes</span>) </span>{
      nodes.circle.remove();
    },
    update: <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">nodes</span>) </span>{
      nodes.circle.setStyle(<span class="hljs-string">"fillStyle"</span>, <span class="hljs-string">"red"</span>);
    }
</code></pre><p>Now, just copy the below code and paste it below the place where you declared joinRef</p>
<pre><code>setTimeout(() <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> {
  joinRef.<span class="hljs-built_in">push</span>({ id: <span class="hljs-number">4</span>, <span class="hljs-built_in">value</span>: <span class="hljs-number">70</span> });
}, <span class="hljs-number">1000</span>);
</code></pre><p>At present, you might be able to see a new circle in an orange colour after a delay of atleast 1 second. So what happened?? Well, i2djs saw that we had pushed some new data element and hence it triggered the entry action with the data which we added, so we got a new circle added to the dom.</p>
<p>Now, copy the below code.</p>
<pre><code>setTimeout(() <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> {
  joinRef.<span class="hljs-built_in">pop</span>();
}, <span class="hljs-number">2000</span>);
</code></pre><p>The above code should remove the newly inserted data element which you had just inserted. What happened behind the scene was that the exit function was triggered which consequently deleted the node representing the respective circle from the dom. </p>
<p>Now, would you like to maybe make the circle bigger, or maybe change its radius, you can do all these stuffs in update action and trigger it using the below code.  But for now, we are just changing the colour to red</p>
<pre><code><span class="hljs-built_in">setTimeout</span>(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
  joinRef.update();
}, <span class="hljs-number">3000</span>);
</code></pre><p>Now, suppose if you would like to remove multiple elements from the dom, which is not possible using pop, for those scenarios you can just refer the below code.</p>
<pre><code><span class="hljs-built_in">setTimeout</span>(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
  joinRef.remove([data[<span class="hljs-number">1</span>], data[<span class="hljs-number">2</span>]]);
}, <span class="hljs-number">4000</span>);
</code></pre><p>What we are doing in the above code is that we are removing two elements based on their index in our provided data. As an important thing to keep in mind is that we need to provide elements which we are gonna remove through reference and not by value.</p>
<p>As an example, below code is not gonna work.</p>
<pre><code><span class="hljs-string">setTimeout(()</span> <span class="hljs-string">=&gt;</span> {
  <span class="hljs-string">joinRef.remove(</span>[
    {
      <span class="hljs-attr">id:</span> <span class="hljs-number">2</span>,
      <span class="hljs-attr">value:</span> <span class="hljs-number">30</span>
    },
    {
      <span class="hljs-attr">id:</span> <span class="hljs-number">3</span>,
      <span class="hljs-attr">value:</span> <span class="hljs-number">40</span>
    }
  ]<span class="hljs-string">);</span>
}<span class="hljs-string">,</span> <span class="hljs-number">4000</span><span class="hljs-string">);</span>
</code></pre><p>Now, let us suppose, we want to manipulate the <strong>data</strong> i.e. remove some objects and add some other objects to the <strong>data</strong> array. </p>
<pre><code><span class="hljs-string">setTimeout(()</span> <span class="hljs-string">=&gt;</span> {
  <span class="hljs-string">data</span> <span class="hljs-string">=</span> [
    {
      <span class="hljs-attr">id:</span> <span class="hljs-number">4</span>,
      <span class="hljs-attr">value:</span> <span class="hljs-number">50</span>
    },
    {
      <span class="hljs-attr">id:</span> <span class="hljs-number">5</span>,
      <span class="hljs-attr">value:</span> <span class="hljs-number">60</span>
    },
    {
      <span class="hljs-attr">id:</span> <span class="hljs-number">6</span>,
      <span class="hljs-attr">value:</span> <span class="hljs-number">70</span>
    }
  ]<span class="hljs-string">;</span>

}<span class="hljs-string">,</span> <span class="hljs-number">5000</span><span class="hljs-string">);</span>
</code></pre><p>Unsurprisingly, our elements will not be updated. So, to tell i2djs to re-render the elements based on the updated <strong>data</strong>, we need to write the below code after <strong>data</strong>.</p>
<pre><code>joinRef.join(data);
</code></pre><p>So, hopefully, we will be able to see new orange circles.</p>
<p>The final code  for this post can be found in the below codepen link. </p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/MohitToshniwal/pen/yLvoaWJ?editors=0010">https://codepen.io/MohitToshniwal/pen/yLvoaWJ?editors=0010</a></div>
<p>And if you would like to see multiple elements, bound with the same data, you can check out the below codepen. In that codepen, I have created a text which is bound to the <strong>value</strong> key in the data we have provided.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/MohitToshniwal/pen/XWZpqXZ?editors=0110">https://codepen.io/MohitToshniwal/pen/XWZpqXZ?editors=0110</a></div>
<p>That's it for now. We will catch up very soon with a new post. And if you all had anything to add which could help me improve my technical writing skills. Do comment it. I am always open for constructive criticism. Thanks for reading till here😁.</p>
<p>Reference links:</p>
<ul>
<li><a target="_blank" href="https://nswamy14.gitbook.io/i2djs/api-reference/join-action">Join-action Api</a></li>
</ul>
]]></content:encoded></item></channel></rss>