<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>exclude elements &#8211; Sibeesh Passion</title>
	<atom:link href="https://www.sibeeshpassion.com/tag/exclude-elements/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Wed, 05 Aug 2015 08:47:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>exclude elements &#8211; Sibeesh Passion</title>
	<link>https://www.sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Find And Exclude Element From Array</title>
		<link>https://www.sibeeshpassion.com/find-and-exclude-element-from-array/</link>
					<comments>https://www.sibeeshpassion.com/find-and-exclude-element-from-array/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Wed, 05 Aug 2015 00:50:47 +0000</pubDate>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[exclude elements]]></category>
		<category><![CDATA[jquery array]]></category>
		<category><![CDATA[JQuery Click]]></category>
		<category><![CDATA[jquery functions]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=7772</guid>

					<description><![CDATA[In this post we well discuss about finding and excluding element from JQuery Array. We all worked in a JQuery. Sometimes we works in JQuery Arrays too. Right? Consider we have an array, and in that array we need to exclude a particular element and create a new array without excluded element. What we will do? We will use a for loop and just loop through the array,apply some conditions and if a criteria matches, we will do some operation right? Here I am going to share you an another way that we can achieve this by using a function [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this post we well discuss about finding and excluding element from JQuery Array. We all worked in a JQuery. Sometimes we works in JQuery Arrays too. Right? Consider we have an array, and in that array we need to exclude a particular element and create a new array without excluded element. What we will do? We will use a for loop and just loop through the array,apply some conditions and if a criteria matches, we will do some operation right? Here I am going to share you an another way that we can achieve this by using a function called <em>grep</em> in JQuery. Normally <em>grep</em> function act as <em>each</em> in JQuery. </p>
<p><strong>Backgroud</strong></p>
<p>I am working in a client side application where there are lots of client side arrays and variables. We handle our entire client side processes by using JQuery. I usually go through the operation of finding and removing array elements using JQuery. I thought it would be better if I share some knowledge about that here. I hope someone will find it is useful.</p>
<p><strong>Using the code</strong></p>
<p>To start with you need to include jquery reference.</p>
<p>[js]<br />
 &lt;script src=&quot;https://code.jquery.com/jquery-2.1.4.min.js&quot;&gt;&lt;/script&gt;<br />
[/js]</p>
<p>Now we need an array right? Consider following is our array.</p>
<p>[js]<br />
var myArray = [&#8216;Monday&#8217;,&#8217;Tuesday&#8217;,&#8217;Wednesday&#8217;,&#8217;Thursday&#8217;,&#8217;Friday&#8217;,&#8217;Saturday&#8217;,&#8217;Sunday&#8217;]<br />
[/js]</p>
<p>Next, we will formulate this array to a HTML table, so that the visualization will be perfect. To do this we will have a function, which will just convert the array element to HTML table. Following is our function body.</p>
<p>[js]<br />
 function buildTable(array,message){<br />
	      var html='&lt;table&gt;&lt;caption&gt;&#8217;+message+'&lt;/caption&gt;&lt;tr&gt;&#8217;;<br />
		  for(var i=0;i&lt;array.length;i++)<br />
		  {<br />
			html+='&lt;td&gt;&#8217;+array[i]+'&lt;/td&gt;&#8217;;<br />
		  }<br />
		  html+='&lt;/tr&gt;&lt;/table&gt;&#8217;;<br />
		  $(&quot;#body&quot;).html(html);<br />
	   }<br />
[/js]	 </p>
<p>As you can see, the parameters for this functions are, an array and a caption message.<br />
Now we need to call this unction right?	 </p>
<p>[js]<br />
 var myArray = [&#8216;Monday&#8217;,&#8217;Tuesday&#8217;,&#8217;Wednesday&#8217;,&#8217;Thursday&#8217;,&#8217;Friday&#8217;,&#8217;Saturday&#8217;,&#8217;Sunday&#8217;]<br />
			var message=&quot;My Array Elements Before Removing&quot;;<br />
			buildTable(myArray,message);<br />
[/js]	 	</p>
<p>Style out HTML table by giving the preceding styles.	 </p>
<p>[css]<br />
 &lt;style&gt;<br />
		  tr{<br />
		     border:1px solid #ccc;<br />
		  }<br />
		  td{<br />
			 border:1px solid #ccc;<br />
			 padding: 10px;<br />
		  }<br />
		  #body{<br />
		    margin: 30px;<br />
		  }<br />
		  #click{<br />
		    margin: 30px;<br />
			cursor:pointer;<br />
		  }</p>
<p>      &lt;/style&gt;<br />
[/css]	 	 </p>
<p>So our output will be as follows. 	</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/07/Exclude_or_remove_array_element_from_array.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/07/Exclude_or_remove_array_element_from_array-300x48.png" alt="Exclude_or_remove_array_element_from_array" width="300" height="48" class="alignnone size-medium wp-image-7782" srcset="/wp-content/uploads/2015/07/Exclude_or_remove_array_element_from_array-300x48.png 300w, /wp-content/uploads/2015/07/Exclude_or_remove_array_element_from_array-400x64.png 400w, /wp-content/uploads/2015/07/Exclude_or_remove_array_element_from_array.png 597w" sizes="(max-width: 300px) 100vw, 300px" /></a>	</p>
<p>Now we need to fire a click event in which we will find out which element is to be excluded from the array, and finally assign new element set to our existing array. 	</p>
<p>[html]<br />
&lt;a hrefe=&quot;#&quot; id=&quot;click&quot;&gt;Click To Remove&lt;/a&gt;<br />
[/html]	 	 </p>
<p>[js]<br />
$(&quot;#click&quot;).click(function(){<br />
				var message=&quot;My Array Elements After Removing&quot;;<br />
				var excludedElement = [&#8216;Thursday&#8217;];<br />
				myArray = jQuery.grep(myArray, function(value) {<br />
				return value != excludedElement;<br />
			    });<br />
			    buildTable(myArray,message);<br />
			});<br />
[/js]	 </p>
<p>Here we are finding the element <em>&#8216;Thursday&#8217;</em> which we saved to a variable as follows.</p>
<p>[js]<br />
var excludedElement = [&#8216;Thursday&#8217;];<br />
[/js]	 	</p>
<p>Now our real here is <em>jQuery.grep</em> , which returns our new array with filtered data.</p>
<p>[js]<br />
return value != excludedElement;<br />
[/js]	 </p>
<p>And then we are calling our <em>buildTable</em> function to formulate our new array to a HTML table. Once we call it we will get an output as follows.	 	</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/07/Exclude_or_remove_array_element_from_array_after.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/07/Exclude_or_remove_array_element_from_array_after-300x60.png" alt="Exclude_or_remove_array_element_from_array_after" width="300" height="60" class="alignnone size-medium wp-image-7792" srcset="/wp-content/uploads/2015/07/Exclude_or_remove_array_element_from_array_after-300x60.png 300w, /wp-content/uploads/2015/07/Exclude_or_remove_array_element_from_array_after-400x81.png 400w, /wp-content/uploads/2015/07/Exclude_or_remove_array_element_from_array_after.png 501w" sizes="(max-width: 300px) 100vw, 300px" /></a>	 </p>
<p><strong>Complete Code</strong>	 	</p>
<p>[html]<br />
&lt;html&gt;<br />
   &lt;head&gt;<br />
      &lt;title&gt;Remove Elements From An Array using JQuery- Sibeesh Passion&lt;/title&gt;<br />
      &lt;style&gt;<br />
		  tr{<br />
		     border:1px solid #ccc;<br />
		  }<br />
		  td{<br />
			 border:1px solid #ccc;<br />
			 padding: 10px;<br />
		  }<br />
		  #body{<br />
		    margin: 30px;<br />
		  }<br />
		  #click{<br />
		    margin: 30px;<br />
			cursor:pointer;<br />
		  }</p>
<p>      &lt;/style&gt;<br />
      &lt;script src=&quot;https://code.jquery.com/jquery-2.1.4.min.js&quot;&gt;&lt;/script&gt;<br />
   &lt;/head&gt;<br />
   &lt;body&gt;<br />
   &lt;a hrefe=&quot;#&quot; id=&quot;click&quot;&gt;Click To Remove&lt;/a&gt;<br />
   &lt;div id=&quot;body&quot;&gt;&lt;/div&gt;<br />
      &lt;script&gt;<br />
       $(document).ready(function(){<br />
		    var myArray = [&#8216;Monday&#8217;,&#8217;Tuesday&#8217;,&#8217;Wednesday&#8217;,&#8217;Thursday&#8217;,&#8217;Friday&#8217;,&#8217;Saturday&#8217;,&#8217;Sunday&#8217;]<br />
			var message=&quot;My Array Elements Before Removing&quot;;<br />
			buildTable(myArray,message);</p>
<p>			$(&quot;#click&quot;).click(function(){<br />
				var message=&quot;My Array Elements After Removing&quot;;<br />
				var excludedElement = [&#8216;Thursday&#8217;];<br />
				myArray = jQuery.grep(myArray, function(value) {<br />
				return value != excludedElement;<br />
			    });<br />
			    buildTable(myArray,message);<br />
			});<br />
	   });<br />
	   function buildTable(array,message){<br />
	      var html='&lt;table&gt;&lt;caption&gt;&#8217;+message+'&lt;/caption&gt;&lt;tr&gt;&#8217;;<br />
		  for(var i=0;i&lt;array.length;i++)<br />
		  {<br />
			html+='&lt;td&gt;&#8217;+array[i]+'&lt;/td&gt;&#8217;;<br />
		  }<br />
		  html+='&lt;/tr&gt;&lt;/table&gt;&#8217;;<br />
		  $(&quot;#body&quot;).html(html);<br />
	   }<br />
      &lt;/script&gt;</p>
<p>   &lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]	 </p>
<p><strong>Demo</strong></p>
<p>Please find out the demo in jsfiddle here: <a href="http://jsfiddle.net/sibeeshvenu/099odrbq/" target="_blank">Exclude or remove elements</a></p>
<p><strong>Conclusion</strong>	</p>
<p>I hope you liked this article. Please share me your feedback. It is always welcomed. Thanks in advance.	 </p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/find-and-exclude-element-from-array/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
