<?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>Remove An Array Element By Index &#8211; Sibeesh Passion</title>
	<atom:link href="https://www.sibeeshpassion.com/tag/remove-an-array-element-by-index/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Fri, 07 Aug 2015 10:44:01 +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>Remove An Array Element By Index &#8211; Sibeesh Passion</title>
	<link>https://www.sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Remove An Array Element By Index</title>
		<link>https://www.sibeeshpassion.com/remove-an-array-element-by-index/</link>
					<comments>https://www.sibeeshpassion.com/remove-an-array-element-by-index/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Fri, 07 Aug 2015 00:30:03 +0000</pubDate>
				<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[jquery array]]></category>
		<category><![CDATA[jquery splice]]></category>
		<category><![CDATA[Remove An Array Element By Index]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=8161</guid>

					<description><![CDATA[In this article, we will see how we can remove an array element by index. We all work with client side array right? What will you do if you need to remove an array element?It will be easy for you to do, if you know the index of the element which we need to delete from the array. Here we are going to discuss that. We will give an option to select the index, and will take that value, and then we will delete the array. Simple right?I hope you will like this article. Using the code Create some elements [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this article, we will see how we can remove an array element by index. We all work with client side array right? What will you do if you need to remove an array element?It will be easy for you to do, if you know the index of the element which we need to delete from the array. Here we are going to discuss that. We will give an option to select the index, and will take that value, and then we will delete the array. Simple right?I hope you will like this article. </p>
<p><strong>Using the code</strong></p>
<p><strong>Create some elements</strong></p>
<p>[html]<br />
&lt;button id=&quot;loadAndShow&quot;&gt;Load Array And Show&lt;/button&gt;&lt;br /&gt;&lt;br /&gt;<br />
    &lt;div id=&quot;divloadAndShow&quot;&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;<br />
    &lt;input type=&quot;number&quot; id=&quot;number&quot; /&gt;&lt;br /&gt;&lt;br /&gt;<br />
    &lt;button id=&quot;RemoveAndShow&quot;&gt;Remove And Show&lt;/button&gt;&lt;br /&gt;&lt;br /&gt;<br />
    &lt;div id=&quot;divRemoveAndShow&quot;&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;<br />
[/html]</p>
<p><em>Add CSS</em></p>
<p>[css]<br />
 &lt;style&gt;<br />
        div {<br />
            display: none;<br />
        }<br />
    &lt;/style&gt;<br />
[/css]</p>
<p><strong>Add the scripts</strong></p>
<p>[js]<br />
    &lt;script&gt;<br />
        var myJSON = [];<br />
        function removeArrayElementByIndex(myArray, index) {<br />
            myArray.splice(index, 1);<br />
            $(&#8216;#divRemoveAndShow&#8217;).html(&#8216;Removed from Array and JSON string is  &#8216;).append(JSON.stringify(myArray)).show();<br />
            myJSON = myArray<br />
        }<br />
        $(function () {<br />
            $(&#8216;#RemoveAndShow&#8217;).hide();<br />
            $(&#8216;#number&#8217;).hide();<br />
            $(&#8216;#loadAndShow&#8217;).click(function () {<br />
                $(&#8216;#RemoveAndShow&#8217;).show();<br />
                $(&#8216;#number&#8217;).show().val(0);<br />
                $(&#8216;#divloadAndShow&#8217;).html(&#8216;Loaded to Array and JSON string is  &#8216;).append(&#8216;[{ &quot;name&quot;: &quot;2014&quot;, &quot;level&quot;: 1 }, { &quot;name&quot;: &quot;4&quot;, &quot;level&quot;: 2 }, { &quot;name&quot;: &quot;12&quot;, &quot;level&quot;: 3 }]&#8217;).show();<br />
                myJSON = $.parseJSON(&#8216;[{ &quot;name&quot;: &quot;2014&quot;, &quot;level&quot;: 1 }, { &quot;name&quot;: &quot;4&quot;, &quot;level&quot;: 2 }, { &quot;name&quot;: &quot;12&quot;, &quot;level&quot;: 3 }]&#8217;);<br />
            });<br />
            $(&#8216;#RemoveAndShow&#8217;).click(function () {<br />
                removeArrayElementByIndex(myJSON, $(&#8216;#number&#8217;).val());<br />
            });<br />
        });<br />
    &lt;/script&gt;<br />
[/js]</p>
<p>In the above code you can find out a function <em>removeArrayElementByIndex</em> which accepts our array and the index as arguments. </p>
<p>[js]<br />
 function removeArrayElementByIndex(myArray, index) {<br />
            myArray.splice(index, 1);<br />
            $(&#8216;#divRemoveAndShow&#8217;).html(&#8216;Removed from Array and JSON string is  &#8216;).append(JSON.stringify(myArray)).show();<br />
            myJSON = myArray<br />
        }<br />
[/js]</p>
<p>When you click on the button <em>loadAndShow</em> , we will load the array and shows the contents. </p>
<p>[js]<br />
//This is the data we load<br />
[{ &quot;name&quot;: &quot;2014&quot;, &quot;level&quot;: 1 }, { &quot;name&quot;: &quot;4&quot;, &quot;level&quot;: 2 }, { &quot;name&quot;: &quot;12&quot;, &quot;level&quot;: 3 }]<br />
[/js]</p>
<p>And if you click on the button <em>RemoveAndShow</em> we will delete the array by passing the array and index to the function  <em>removeArrayElementByIndex</em> </p>
<p><strong>Complete code</strong></p>
<p>[html]<br />
&lt;!DOCTYPE html&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
    &lt;title&gt;Remove an array element by its index&lt;/title&gt;<br />
    &lt;script src=&quot;jquery-2.0.2.min.js&quot;&gt;&lt;/script&gt;<br />
    &lt;style&gt;<br />
        div {<br />
            display: none;<br />
        }<br />
    &lt;/style&gt;<br />
    &lt;script&gt;<br />
        var myJSON = [];<br />
        function removeArrayElementByIndex(myArray, index) {<br />
            myArray.splice(index, 1);<br />
            $(&#8216;#divRemoveAndShow&#8217;).html(&#8216;Removed from Array and JSON string is  &#8216;).append(JSON.stringify(myArray)).show();<br />
            myJSON = myArray<br />
        }<br />
        $(function () {<br />
            $(&#8216;#RemoveAndShow&#8217;).hide();<br />
            $(&#8216;#number&#8217;).hide();<br />
            $(&#8216;#loadAndShow&#8217;).click(function () {<br />
                $(&#8216;#RemoveAndShow&#8217;).show();<br />
                $(&#8216;#number&#8217;).show().val(0);<br />
                $(&#8216;#divloadAndShow&#8217;).html(&#8216;Loaded to Array and JSON string is  &#8216;).append(&#8216;[{ &quot;name&quot;: &quot;2014&quot;, &quot;level&quot;: 1 }, { &quot;name&quot;: &quot;4&quot;, &quot;level&quot;: 2 }, { &quot;name&quot;: &quot;12&quot;, &quot;level&quot;: 3 }]&#8217;).show();<br />
                myJSON = $.parseJSON(&#8216;[{ &quot;name&quot;: &quot;2014&quot;, &quot;level&quot;: 1 }, { &quot;name&quot;: &quot;4&quot;, &quot;level&quot;: 2 }, { &quot;name&quot;: &quot;12&quot;, &quot;level&quot;: 3 }]&#8217;);<br />
            });<br />
            $(&#8216;#RemoveAndShow&#8217;).click(function () {<br />
                removeArrayElementByIndex(myJSON, $(&#8216;#number&#8217;).val());<br />
            });<br />
        });<br />
    &lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
    &lt;button id=&quot;loadAndShow&quot;&gt;Load Array And Show&lt;/button&gt;&lt;br /&gt;&lt;br /&gt;<br />
    &lt;div id=&quot;divloadAndShow&quot;&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;<br />
    &lt;input type=&quot;number&quot; id=&quot;number&quot; /&gt;&lt;br /&gt;&lt;br /&gt;<br />
    &lt;button id=&quot;RemoveAndShow&quot;&gt;Remove And Show&lt;/button&gt;&lt;br /&gt;&lt;br /&gt;<br />
    &lt;div id=&quot;divRemoveAndShow&quot;&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]</p>
<p><strong>Output</strong></p>
<div id="attachment_8211" style="width: 310px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/07/Remove_Array_Elements_By_Index.png"><img decoding="async" aria-describedby="caption-attachment-8211" src="http://sibeeshpassion.com/wp-content/uploads/2015/07/Remove_Array_Elements_By_Index-300x86.png" alt="Remove an array element by its index" width="300" height="86" class="size-medium wp-image-8211" srcset="/wp-content/uploads/2015/07/Remove_Array_Elements_By_Index-300x86.png 300w, /wp-content/uploads/2015/07/Remove_Array_Elements_By_Index-400x115.png 400w, /wp-content/uploads/2015/07/Remove_Array_Elements_By_Index.png 510w" sizes="(max-width: 300px) 100vw, 300px" /></a><p id="caption-attachment-8211" class="wp-caption-text">Remove an array element by its index</p></div>
<div id="attachment_8221" style="width: 310px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/07/Remove_Array_Elements_By_Index1.png"><img decoding="async" aria-describedby="caption-attachment-8221" src="http://sibeeshpassion.com/wp-content/uploads/2015/07/Remove_Array_Elements_By_Index1-300x88.png" alt="Remove an array element by its index" width="300" height="88" class="size-medium wp-image-8221" srcset="/wp-content/uploads/2015/07/Remove_Array_Elements_By_Index1-300x88.png 300w, /wp-content/uploads/2015/07/Remove_Array_Elements_By_Index1-768x226.png 768w, /wp-content/uploads/2015/07/Remove_Array_Elements_By_Index1-400x118.png 400w, /wp-content/uploads/2015/07/Remove_Array_Elements_By_Index1.png 871w" sizes="(max-width: 300px) 100vw, 300px" /></a><p id="caption-attachment-8221" class="wp-caption-text">Remove an array element by its index</p></div>
<div id="attachment_8222" style="width: 310px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/07/Remove_Array_Elements_By_Index2.png"><img decoding="async" aria-describedby="caption-attachment-8222" src="http://sibeeshpassion.com/wp-content/uploads/2015/07/Remove_Array_Elements_By_Index2-300x109.png" alt="Remove an array element by its index" width="300" height="109" class="size-medium wp-image-8222" srcset="/wp-content/uploads/2015/07/Remove_Array_Elements_By_Index2-300x109.png 300w, /wp-content/uploads/2015/07/Remove_Array_Elements_By_Index2-768x279.png 768w, /wp-content/uploads/2015/07/Remove_Array_Elements_By_Index2-400x146.png 400w, /wp-content/uploads/2015/07/Remove_Array_Elements_By_Index2.png 852w" sizes="(max-width: 300px) 100vw, 300px" /></a><p id="caption-attachment-8222" class="wp-caption-text">Remove an array element by its index</p></div>
<div id="attachment_8231" style="width: 310px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2015/07/Remove_Array_Elements_By_Index3.png"><img decoding="async" aria-describedby="caption-attachment-8231" src="http://sibeeshpassion.com/wp-content/uploads/2015/07/Remove_Array_Elements_By_Index3-300x101.png" alt="Remove an array element by its index" width="300" height="101" class="size-medium wp-image-8231" srcset="/wp-content/uploads/2015/07/Remove_Array_Elements_By_Index3-300x101.png 300w, /wp-content/uploads/2015/07/Remove_Array_Elements_By_Index3-768x260.png 768w, /wp-content/uploads/2015/07/Remove_Array_Elements_By_Index3-400x135.png 400w, /wp-content/uploads/2015/07/Remove_Array_Elements_By_Index3.png 828w" sizes="(max-width: 300px) 100vw, 300px" /></a><p id="caption-attachment-8231" class="wp-caption-text">Remove an array element by its index</p></div>
<p><strong>Conclusion</strong></p>
<p>I hope someone found it is useful. Please share me your feedback. Thanks in advance.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/remove-an-array-element-by-index/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
