<?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>Lodash Archives - AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</title>
	<atom:link href="https://atcodex.com/tag/lodash/feed/" rel="self" type="application/rss+xml" />
	<link>https://atcodex.com/tag/lodash/</link>
	<description>Achieve financial success without sacrificing well-being! AtCodex provides actionable strategies for managing money, time, and personal growth—all in one place.</description>
	<lastBuildDate>Sat, 28 Aug 2021 17:14:37 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://atcodex.com/wp-content/uploads/2020/05/cropped-New-Project-1-32x32.png</url>
	<title>Lodash Archives - AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</title>
	<link>https://atcodex.com/tag/lodash/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Remove multiple elements from an array in Javascript/jQuery</title>
		<link>https://atcodex.com/php/remove-multiple-elements-from-an-array-in-javascript-jquery/</link>
		
		<dc:creator><![CDATA[atcodex]]></dc:creator>
		<pubDate>Mon, 28 Sep 2020 17:31:11 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[Lodash]]></category>
		<category><![CDATA[Underscore]]></category>
		<guid isPermaLink="false">https://atcodex.com/?p=1045</guid>

					<description><![CDATA[<p>In this post, we will learn how to Remove multiple elements from an array using Javascript or jQuery give with an example. We can simply remove elements from an array &#8230; </p>
<p>The post <a href="https://atcodex.com/php/remove-multiple-elements-from-an-array-in-javascript-jquery/">Remove multiple elements from an array in Javascript/jQuery</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">In this post, we will learn how to Remove multiple elements from an array using Javascript or jQuery give with an example. We can simply remove elements from an array using javascript. Below in the post, we have tried different methods to do the same.</p>



<p class="wp-block-paragraph">Let&#8217;s suppose we have an array in which and we want to remove some particular element from the array without refreshing the page.  In that case, we have to use javascript and jquery to remove the element from the array. Because if we go for server-side language then we have to refresh the page or need to get done the same thing with the help of AJAX and backend language. Which is a kind of long and boring task to do. We can simply use javascript, jquery, and some of the other javascript libraries to do it.</p>



<p class="wp-block-paragraph">Following are the some example we are providing to make you  understand about the topic.</p>



<h2 class="wp-block-heading">Remove element using Vanilla JavaScript</h2>



<p class="wp-block-paragraph">In first, let&#8217;s remove the element using simple javascript and jquery, In this, we will use Array.prototype.remove, grep() and inArray() to remove multiple as well as the duplicate value from the array in jquery. However, you can check <a href="https://atcodex.com/how-to/how-to-remove-duplicate-values-from-an-array-in-php/" target="_blank" rel="noreferrer noopener">How to remove duplicate values from an array in PHP</a></p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">&lt;!DOCTYPE html>
&lt;html>
&lt;head>
   &lt;title>Jquery Remove Multiple Values from Array Example&lt;/title>
   &lt;script src="https://code.jquery.com/jquery-1.12.4.js">&lt;/script>
&lt;/head>
&lt;body>
  
&lt;script type="text/javascript">
    var sites = [ "website1.com", "website2.com", "website3.com", "website4.com" ];
  
    Array.prototype.remove = function(){
        var args = Array.apply(null, arguments); 
   
        return $.grep(this, function(value) {
           return $.inArray(value, args) &lt; 0;
        });
    }
  
    sitesNew = sites.remove("website2.com", "website3.com");
  
    console.log(sitesNew);
&lt;/script>
  
&lt;/body>
&lt;/html></pre>



<p class="wp-block-paragraph">Output</p>



<figure class="wp-block-image size-large is-resized is-style-default"><img fetchpriority="high" decoding="async" src="https://atcodex.com/wp-content/uploads/2020/09/Untitled.png" alt="output in console" class="wp-image-1056" width="590" height="330" srcset="https://atcodex.com/wp-content/uploads/2020/09/Untitled.png 590w, https://atcodex.com/wp-content/uploads/2020/09/Untitled-300x168.png 300w" sizes="(max-width: 590px) 100vw, 590px" /></figure>



<h2 class="wp-block-heading">Remove element using Using Lodash</h2>



<p class="wp-block-paragraph">To remove an element, we can use an external javascript library called Lodash. Lodash has the <code><a href="https://lodash.com/docs/#remove" target="_blank" rel="noreferrer noopener">remove</a>()</code> method which is very easy to use. All other methods in the Lodash are very easy to use and helpful which can done job for you in a second. You do not need to break the array  and manipulate for getting some work done in javascript. It have very helpful built in methods which you can use in any situation in the programming.</p>



<p class="wp-block-paragraph">In the below code  we are just passing the array in _.remove() and in which we have defined callback function when passed argument is == to 3.  </p>



<p class="wp-block-paragraph"><strong>NOTE : It make the changes in the existing array value</strong>.</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">var arr = [1, 2, 3, 3, 4, 5];
_.remove(arr, function(e) {
    return e === 3;
});
console.log(arr);

// Output:
// [ 1, 2, 4, 5 ]</pre>



<p class="wp-block-paragraph"></p>



<h2 class="wp-block-heading">Remove element using Using Underscore</h2>



<p class="wp-block-paragraph">We can use Underscore library to solve the same problem. It has _.reject method which is same like _.remove() method in the Lodash. It works similarly like Lodash with some difference which is : it returns the new array after removing the passed value in the array. Old array value remains same. </p>



<p class="wp-block-paragraph">See the following code for an example:</p>



<pre class="EnlighterJSRAW" data-enlighter-language="generic" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">var arr = [1, 2, 3, 3, 4, 5];
var ret = _.reject(arr, function(e) {
    return e === 3;
});
console.log(arr);
console.log(ret);

// Output:
// [ 1, 2, 3, 3, 4, 5 ]
// [ 1, 2, 4, 5 ]
</pre>



<h2 class="wp-block-heading">Conclusion</h2>



<p class="wp-block-paragraph">We have explained 3 different method and by using them you can remove the one or more elements from the array in simple way. I hope you guys have liked the post, if you have any suggestion please comment below., i would love to help you.</p>
<p>The post <a href="https://atcodex.com/php/remove-multiple-elements-from-an-array-in-javascript-jquery/">Remove multiple elements from an array in Javascript/jQuery</a> appeared first on <a href="https://atcodex.com">AtCodex: Empowering Your Financial Journey &amp; Personal Well-Being</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
