<?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>code &#8211; Snehal.Life</title>
	<atom:link href="https://snehaltayde.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>https://snehaltayde.com</link>
	<description></description>
	<lastBuildDate>Thu, 12 Sep 2024 14:40: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>https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/cropped-9735a45c-bd28-4373-81a7-2550e7ce9bbb.jpg?fit=32%2C32&#038;ssl=1</url>
	<title>code &#8211; Snehal.Life</title>
	<link>https://snehaltayde.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">175116317</site>	<item>
		<title>Autofill State Based on Postal Code in WooCommerce Checkout: A Step-by-Step Guide</title>
		<link>https://snehaltayde.com/autofill-state-based-on-postal-code-in-woocommerce-checkout-a-step-by-step-guide/</link>
					<comments>https://snehaltayde.com/autofill-state-based-on-postal-code-in-woocommerce-checkout-a-step-by-step-guide/#respond</comments>
		
		<dc:creator><![CDATA[Snehalkumar]]></dc:creator>
		<pubDate>Tue, 25 Jul 2023 17:12:06 +0000</pubDate>
				<category><![CDATA[code]]></category>
		<guid isPermaLink="false">https://snehaltayde.com/?p=780</guid>

					<description><![CDATA[WooCommerce, a highly customizable eCommerce platform, allows you to provide a seamless user experience for]]></description>
										<content:encoded><![CDATA[
<p>WooCommerce, a highly customizable eCommerce platform, allows you to provide a seamless user experience for your customers. One such optimization is autofilling the billing state based on the postal code entered by the customer. In this blog post, we&#8217;ll walk you through the steps on how to do this using JavaScript, jQuery, and an external API.</p>



<pre class="wp-block-code"><code>&lt;script&gt;
	jQuery(document).ready(function($) {
    jQuery(window).on('load', function() {
        // Generate state map
        var stateMap = {};
        jQuery('#billing_state option').each(function() {
            var stateName = $(this).text();
            var stateCode = $(this).val();
            if(stateName &amp;&amp; stateCode) {
                stateMap&#91;stateName] = stateCode;
            }
        });

        // Listen for change on the billing_postcode input field
        jQuery('#billing_postcode').change(function() {
            // Get the value of the field
            var pincode = $(this).val();

            // Make sure pincode isn't empty
            if(pincode != '') {
                // AJAX call to the API
                jQuery.ajax({
                    url: 'https://api.postalpincode.in/pincode/' + pincode,
                    type: 'GET',
                    success: function(response) {
                        // Check if Status is Success
                        if(response&#91;0].Status === 'Success') {
                            // Get the state from the first Post Office
                            var state = response&#91;0].PostOffice&#91;0].State;

														console.log(state)

                            // Map the state to its code
                            var stateCode = stateMap&#91;state];

                            // Update the billing_state field
                            if (stateCode) {
                                      jQuery('#billing_state').val(stateCode).trigger('change');
                            }
                        }
                    },
                    error: function() {
                        // Handle error here
                        console.log('Error occurred while fetching pincode details.');
                    }
                });
            }
        });
    });
});


&lt;/script&gt;
</code></pre>



<p>Step 1: Setting Up: First, we use the <code>jQuery(document).ready</code> function, which ensures that our code will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute.</p>



<p>Step 2: Initializing the State Map: We initialize an empty JavaScript object <code>stateMap</code> to hold our state names and corresponding state codes. We then loop through each option in the &#8216;billing_state&#8217; dropdown using jQuery&#8217;s <code>.each</code> function. For each option, we fetch the state name (text of the option) and state code (value of the option) and store them in <code>stateMap</code>. This map will be used to convert the state name returned by the API to a state code that WooCommerce can understand.</p>



<p>Step 3: Listening for Changes: We set up a listener on the &#8216;billing_postcode&#8217; input field using jQuery&#8217;s <code>.change</code> function. Whenever a customer enters or changes their postal code, the function inside <code>.change</code> will run.</p>



<p>Step 4: Making the API Request: Inside the <code>.change</code> function, we first retrieve the postal code entered by the customer. Provided that the postal code is not empty, we make an AJAX request to the &#8216;<a href="https://api.postalpincode.in/pincode/">https://api.postalpincode.in/pincode/</a>&#8216; API with the postal code appended to the URL. AJAX allows us to send this HTTP GET request asynchronously without refreshing the page.</p>



<p>Step 5: Processing the API Response: Upon a successful API response, we check if the &#8216;Status&#8217; field of the response is &#8216;Success&#8217;. If it is, we extract the &#8216;State&#8217; field from the first &#8216;PostOffice&#8217; object in the response. This &#8216;State&#8217; field contains the name of the state corresponding to the postal code.</p>



<p>Step 6: Updating the State Field: Using our <code>stateMap</code>, we convert the state name to a state code. If the conversion is successful, we update the &#8216;billing_state&#8217; dropdown to reflect this state code using jQuery&#8217;s <code>.val</code> function. We also trigger a &#8216;change&#8217; event to tell any other scripts listening for changes on this dropdown that the state has been updated.</p>



<p>Step 7: Handling Errors: If there&#8217;s an error with the API request, we log a simple error message to the console. In a production environment, you might want to handle this error more gracefully to enhance user experience.</p>



<p>And there you have it &#8211; a comprehensive guide on autofilling the state field based on the postal code in WooCommerce. Implementing this feature can provide a smoother checkout process for your customers, potentially increasing conversions and customer satisfaction.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://snehaltayde.com/autofill-state-based-on-postal-code-in-woocommerce-checkout-a-step-by-step-guide/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">780</post-id>	</item>
		<item>
		<title>Quantum Computing: A Leap Beyond Traditional Computing</title>
		<link>https://snehaltayde.com/quantum-technology-and-the-fascinating-future-of-computing/</link>
					<comments>https://snehaltayde.com/quantum-technology-and-the-fascinating-future-of-computing/#respond</comments>
		
		<dc:creator><![CDATA[Snehalkumar]]></dc:creator>
		<pubDate>Mon, 12 Jun 2023 16:55:01 +0000</pubDate>
				<category><![CDATA[code]]></category>
		<category><![CDATA[future and tech]]></category>
		<guid isPermaLink="false">https://snehaltayde.com/?p=667</guid>

					<description><![CDATA[In the landscape of computational technology, the name of the game is constant advancement. Over]]></description>
										<content:encoded><![CDATA[
<p>In the landscape of computational technology, the name of the game is constant advancement. Over the years, we&#8217;ve seen the evolution of room-sized computers into palm-sized devices, punch cards into graphical user interfaces, and single-threaded tasks into parallel processing. Now, we&#8217;re on the brink of a new era, heralded by a phenomenon that will eclipse what we thought we knew about computing: quantum computing.</p>



<h2 class="wp-block-heading">Traditional Computing: Analog, Digital, and Hybrid</h2>



<p>Traditional computing encompasses several types of systems, primarily analog, digital, and hybrid computers. Each type has its unique characteristics and applications.</p>



<p><strong>1. Analog Computing:</strong> Analog computers use continuous, physical phenomena to represent information. They process data by measuring physical quantities such as electrical voltage, fluid pressure, or mechanical motion. Analog computers were extensively used in scientific and industrial applications, where they performed complex mathematical calculations by manipulating these physical quantities.</p>



<p><strong>2. Digital Computing:</strong> Digital computers, on the other hand, use discrete values, usually binary digits or &#8220;bits.&#8221; Unlike analog computers, which operate in a continuous manner, digital computers work by counting. They represent all information as numbers and perform operations via binary computation. Digital computers are what most people think of when they refer to a &#8220;computer&#8221; today. They dominate our modern world, enabling everything from scientific research to business, entertainment, and social communication.</p>



<p><strong>3. Hybrid Computing:</strong> Hybrid computers, as the name suggests, are a combination of both analog and digital computers. These computers take advantage of the best of both worlds. They use analog components for quickly processing complex equations and then convert the results into digital form for further manipulation and storage.</p>



<p>Despite the differences among these types, the fundamental principle remains the same: converting real-world data into a format that a machine can understand and process.</p>



<h2 class="wp-block-heading">A New Frontier: Quantum Computing</h2>



<p>Just as digital computing was a revolution that superseded analog computing in many applications, a new era is on the horizon: quantum computing. Quantum computers are different from classical computers in some fundamental ways.</p>



<p><strong>1. Quantum Computing:</strong> Unlike classical computers, quantum computers utilize quantum bits or &#8220;qubits.&#8221; They leverage principles of quantum mechanics, which describes the behavior of atomic and subatomic particles. Unlike bits in a digital computer, which can either be a 0 or a 1, qubits can be both 0 and 1 simultaneously due to a property called superposition. Additionally, they can be entangled, meaning the state of one qubit can instantaneously affect the state of another, no matter the distance between them, due to a phenomenon known as entanglement.</p>



<p>The principles of superposition and entanglement allow quantum computers to process a vast number of possibilities all at once, making them potentially incredibly powerful for certain complex problems. Quantum computing holds the promise to revolutionize fields such as cryptography, optimization, and materials science.</p>



<p><strong>2. Hybrid Quantum-Classical Computing:</strong> Quantum computing&#8217;s nascent technology is often leveraged in conjunction with classical computing to create hybrid systems. These systems use quantum processes to perform specific tasks that are challenging for classical computers, while classical computers handle other computations. This hybrid approach capitalizes on the strengths of both types of computing.</p>



<p>To sum up, the evolution of computing is an intriguing journey of constant innovation and enhancement. Analog and digital systems laid the foundation of computing, and hybrid systems brought the best of both worlds. Now, with the advent of quantum computing, we are on the verge of a new era that can potentially revolutionize the way we process and handle information.</p>



<h2 class="wp-block-heading">Bits and Qubits</h2>



<p>One of the primary distinctions between classical and quantum computing is the difference between bits and qubits.</p>



<p>Bits, in classical computing, can be either a 0 or a 1. These bits are like switches &#8211; they are either on or off.</p>



<p>In contrast, quantum computing&#8217;s qubits are quite different. Thanks to a property of quantum mechanics called superposition, qubits can be both 0 and 1 simultaneously. This state of &#8216;quantum superposition&#8217; allows quantum computers to process a vast number of possibilities at once.</p>



<h2 class="wp-block-heading">Quantum Computer vs. Digital Computer</h2>



<p>Digital or classical computers work by manipulating bits, which exist in a definite state of 0 or 1. Their calculations are sequential, meaning they process one operation at a time.</p>



<p>Quantum computers, however, leverage the peculiar principles of quantum mechanics to process information. They exploit two key features: superposition, as mentioned earlier, and entanglement, which links qubits in such a way that the state of one can instantly affect the state of another, regardless of the distance between them. This simultaneity allows quantum computers to solve complex problems that would be virtually impossible for classical computers to handle within a reasonable timeframe.</p>



<h2 class="wp-block-heading">Quantum Supremacy</h2>



<p>Quantum supremacy, also known as quantum advantage, refers to the point where quantum computers can solve problems significantly faster or more efficiently than classical computers. Quantum supremacy is still a widely debated topic, and as of my knowledge cutoff in September 2021, has not been unequivocally achieved, though significant strides have been made.</p>



<h2 class="wp-block-heading">Risks of Quantum Computing and the Workarounds</h2>



<p>While quantum computing promises extraordinary capabilities, it also presents unique challenges and risks.</p>



<p><strong>1. Decoherence:</strong> Quantum states are delicate and can be easily disturbed by their environment, a phenomenon known as decoherence. Decoherence can cause computational errors and is one of the most significant obstacles to reliable quantum computing. Various techniques, such as error correction algorithms and operating qubits at extremely low temperatures, are being used to mitigate this.</p>



<p><strong>2. Quantum Computing and Encryption:</strong> Quantum computing could potentially break current encryption algorithms, posing a considerable threat to data security. To address this, researchers are developing quantum-resistant algorithms.</p>



<p><strong>3. Resource Intensive:</strong> Quantum computers are resource-intensive and require specific conditions to function. They need to operate at near absolute zero temperatures and require substantial energy inputs.</p>



<h2 class="wp-block-heading">Will Quantum Computers Replace Digital Computers?</h2>



<p>Quantum computers are not intended to replace classical computers, but rather to solve a different class of problems that are intractable or extremely time-consuming on classical machines. These include problems in cryptography, material science, drug discovery, and optimization problems. For day-to-day tasks like email, web browsing, and word processing, classical computers are more than capable and energy-efficient.</p>



<h2 class="wp-block-heading">How Far Are We To See Quantum Computers In Use?</h2>



<p>We are still in the early stages of quantum computing. While strides have been made, with companies like IBM, Google, and Microsoft investing heavily in research and development, there is still a long way to go before quantum computers become commonplace.</p>



<h2 class="wp-block-heading">What Problems Will Quantum Computing Be Solving?</h2>



<p>Quantum computers promise to revolutionize various industries. For example, in drug discovery, quantum computers could analyze and simulate molecular structures in ways that are currently impossible for classical computers. In cryptography, quantum computers could crack codes that would take classical computers billions of years. In logistics and operations, quantum computers could optimize complex systems and processes, from traffic flow in a city to supply chains for multinational corporations.</p>



<p>The dawn of quantum computing ushers in an era of opportunities and challenges. As we make strides in this field, we expand the horizons of what&#8217;s computationally possible, paving the way for breakthroughs that can redefine our future. Quantum computing is not just the next step in computing evolution; it&#8217;s a quantum leap.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://snehaltayde.com/quantum-technology-and-the-fascinating-future-of-computing/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">667</post-id>	</item>
		<item>
		<title>Decoding React Hooks: A Step-by-Step Walkthrough</title>
		<link>https://snehaltayde.com/decoding-react-hooks-a-step-by-step-walkthrough/</link>
					<comments>https://snehaltayde.com/decoding-react-hooks-a-step-by-step-walkthrough/#respond</comments>
		
		<dc:creator><![CDATA[Snehalkumar]]></dc:creator>
		<pubDate>Sun, 11 Jun 2023 16:12:32 +0000</pubDate>
				<category><![CDATA[code]]></category>
		<guid isPermaLink="false">https://snehaltayde.com/?p=676</guid>

					<description><![CDATA[React Hooks, introduced in React 16.8, allow you to use state and other React features]]></description>
										<content:encoded><![CDATA[
<p>React Hooks, introduced in React 16.8, allow you to use state and other React features without writing a class. Hooks provide a more direct API to React concepts you already know: props, state, context, refs, and lifecycle. Here&#8217;s a guide to understanding all the built-in hooks in React.</p>



<h2 class="wp-block-heading">1. useState</h2>



<p>The <code>useState</code> hook allows you to add state to your functional components.</p>



<pre class="wp-block-code"><code>import { useState } from 'react';

function Example() {
  const &#91;count, setCount] = useState(0);

  return (
    &lt;div&gt;
      &lt;p&gt;You clicked {count} times&lt;/p&gt;
      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Click me&lt;/button&gt;
    &lt;/div&gt;
  );
}</code></pre>



<h2 class="wp-block-heading">2. useEffect</h2>



<p>The <code>useEffect</code> hook lets you perform side effects in function components, such as data fetching, subscriptions, or manually changing the DOM.</p>



<pre class="wp-block-code"><code>import { useState, useEffect } from 'react';

function Example() {
  const &#91;count, setCount] = useState(0);

  useEffect(() =&gt; {
    document.title = `You clicked ${count} times`;
  });

  return (
    &lt;div&gt;
      &lt;p&gt;You clicked {count} times&lt;/p&gt;
      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Click me&lt;/button&gt;
    &lt;/div&gt;
  );
}</code></pre>



<h2 class="wp-block-heading">3. useContext</h2>



<p>The <code>useContext</code> hook lets you subscribe to React context without introducing nesting.</p>



<pre class="wp-block-code"><code>import { useContext } from 'react';
import { ThemeContext } from './ThemeContext';

function ThemedButton() {
  const theme = useContext(ThemeContext);
  return &lt;button style={{ background: theme.background, color: theme.foreground }}&gt;I'm styled by theme context!&lt;/button&gt;;
}</code></pre>



<h2 class="wp-block-heading">4. useReducer</h2>



<p>The <code>useReducer</code> hook is an alternative to <code>useState</code> that&#8217;s preferable for complex state logic that involves multiple sub-values or when the next state depends on the previous one.</p>



<pre class="wp-block-code"><code>import { useReducer } from 'react';

function reducer(state, action) {
  switch (action.type) {
    case 'increment':
      return {count: state.count + 1};
    case 'decrement':
      return {count: state.count - 1};
    default:
      throw new Error();
  }
}

function Counter() {
  const &#91;state, dispatch] = useReducer(reducer, {count: 0});

  return (
    &lt;&gt;
      Count: {state.count}
      &lt;button onClick={() =&gt; dispatch({type: 'increment'})}&gt;+&lt;/button&gt;
      &lt;button onClick={() =&gt; dispatch({type: 'decrement'})}&gt;-&lt;/button&gt;
    &lt;/&gt;
  );
}</code></pre>



<h2 class="wp-block-heading">5. useCallback</h2>



<p>The <code>useCallback</code> hook returns a memoized version of the callback that only changes if one of the dependencies has changed. This is useful when passing callbacks to optimized child components that rely on reference equality to prevent unnecessary renders.</p>



<pre class="wp-block-code"><code>import { useCallback } from 'react';

function Example({ someProp }) {
  const memoizedCallback = useCallback(() =&gt; {
    doSomething(someProp);
  }, &#91;someProp]);  // Only recreates the callback if `someProp` changes
}</code></pre>



<h2 class="wp-block-heading">6. useMemo</h2>



<p>The <code>useMemo</code> hook returns a memoized value, only re-computing the memoized value when one of the dependencies has changed.</p>



<pre class="wp-block-code"><code>import { useMemo } from 'react';

function Example({ a, b }) {
  const memoizedValue = useMemo(() =&gt; computeExpensiveValue(a, b), &#91;a, b]);  // Only re-runs the

 expensive function if `a` or `b` changes
}</code></pre>



<h2 class="wp-block-heading">7. useRef</h2>



<p>The <code>useRef</code> hook is useful for accessing DOM nodes or keeping any mutable value around, similar to how you’d use instance fields in classes.</p>



<pre class="wp-block-code"><code>import { useRef } from 'react';

function TextInputWithFocusButton() {
  const inputEl = useRef(null);
  const onButtonClick = () =&gt; {
    // `current` points to the mounted text input element
    inputEl.current.focus();
  };
  return (
    &lt;&gt;
      &lt;input ref={inputEl} type="text" /&gt;
      &lt;button onClick={onButtonClick}&gt;Focus the input&lt;/button&gt;
    &lt;/&gt;
  );
}</code></pre>



<h2 class="wp-block-heading">8. useImperativeHandle</h2>



<p>The <code>useImperativeHandle</code> hook customizes the instance value that is exposed to parent components when using ref.</p>



<pre class="wp-block-code"><code>import { useImperativeHandle, useRef, forwardRef } from 'react';

function FancyInput(props, ref) {
  const inputRef = useRef();
  useImperativeHandle(ref, () =&gt; ({
    focus: () =&gt; {
      inputRef.current.focus();
    }
  }));
  return &lt;input ref={inputRef} ... /&gt;;
}

FancyInput = forwardRef(FancyInput);</code></pre>



<h2 class="wp-block-heading">9. useLayoutEffect</h2>



<p>The <code>useLayoutEffect</code> hook is identical to <code>useEffect</code> but it fires synchronously after all DOM mutations. Use this to read layout from the DOM and synchronously re-render. Updates scheduled inside <code>useLayoutEffect</code> will be flushed synchronously, before the browser has a chance to paint.</p>



<pre class="wp-block-code"><code>import { useLayoutEffect } from 'react';

useLayoutEffect(() =&gt; {
  // Your code here. Similar to componentDidMount and componentDidUpdate. 
});</code></pre>



<h2 class="wp-block-heading">10. useDebugValue</h2>



<p>The <code>useDebugValue</code> hook can be used to display a label for custom hooks in React DevTools.</p>



<pre class="wp-block-code"><code>import { useDebugValue } from 'react';

function useFriendStatus(friendID) {
  const isOnline = // Some logic...

  useDebugValue(isOnline ? 'Online' : 'Offline');

  return isOnline;
}</code></pre>



<p>React Hooks are a powerful addition to React, giving you the tools to write your components in a simpler and more intuitive way, without sacrificing any of the power or flexibility of React. Remember, Hooks are completely opt-in and 100% backwards-compatible. You can use Hooks in all your new components, while keeping your old class-based components as they are.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://snehaltayde.com/decoding-react-hooks-a-step-by-step-walkthrough/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">676</post-id>	</item>
		<item>
		<title>Understanding JavaScript Array Methods</title>
		<link>https://snehaltayde.com/javascript-array-methods/</link>
					<comments>https://snehaltayde.com/javascript-array-methods/#respond</comments>
		
		<dc:creator><![CDATA[Snehalkumar]]></dc:creator>
		<pubDate>Sat, 10 Jun 2023 12:22:47 +0000</pubDate>
				<category><![CDATA[code]]></category>
		<guid isPermaLink="false">https://snehaltayde.com/?p=694</guid>

					<description><![CDATA[In the realm of JavaScript, arrays are at the core of managing and manipulating data.]]></description>
										<content:encoded><![CDATA[
<p>In the realm of JavaScript, arrays are at the core of managing and manipulating data. JavaScript provides an array of different methods to work with arrays, making them an indispensable tool in every developer&#8217;s arsenal. This post is designed as a comprehensive guide to understanding and effectively using JavaScript array methods, accompanied by code examples for a hands-on experience. Let&#8217;s explore!</p>



<h2 class="wp-block-heading">01. Array Length</h2>



<p>The array <code>length</code> property in JavaScript is used to determine the number of elements present in an array. It&#8217;s the most basic yet crucial property of an array that helps in iterations and condition checks. Let&#8217;s understand it with a simple code snippet:</p>



<pre class="wp-block-code"><code>let fruits = &#91;'Apple', 'Banana', 'Cherry'];
console.log(fruits.length); // Outputs: 3</code></pre>



<h2 class="wp-block-heading">02. Array toString()</h2>



<p>The <code>toString()</code> method converts an array into a string, separating array elements by commas. This is an efficient way to present array data in a readable format.</p>



<pre class="wp-block-code"><code>let fruits = &#91;'Apple', 'Banana', 'Cherry'];
console.log(fruits.toString()); // Outputs: "Apple,Banana,Cherry"</code></pre>



<h2 class="wp-block-heading">03. Array pop()</h2>



<p>The <code>pop()</code> method removes the last element from an array and returns that element. This method modifies the original array.</p>



<pre class="wp-block-code"><code>let fruits = &#91;'Apple', 'Banana', 'Cherry'];
console.log(fruits.pop()); // Outputs: "Cherry"
console.log(fruits); // Outputs: &#91;"Apple", "Banana"]</code></pre>



<h2 class="wp-block-heading">04. Array push()</h2>



<p>Opposite of <code>pop()</code>, the <code>push()</code> method adds one or more elements to the end of an array and returns the new length of the array.</p>



<pre class="wp-block-code"><code>let fruits = &#91;'Apple', 'Banana'];
console.log(fruits.push('Cherry')); // Outputs: 3
console.log(fruits); // Outputs: &#91;"Apple", "Banana", "Cherry"]</code></pre>



<h2 class="wp-block-heading">05. Array shift()</h2>



<p>The <code>shift()</code> method works similarly to <code>pop()</code>, but instead of removing the last element, it removes the first element from an array and returns that element.</p>



<pre class="wp-block-code"><code>let fruits = &#91;'Apple', 'Banana', 'Cherry'];
console.log(fruits.shift()); // Outputs: "Apple"
console.log(fruits); // Outputs: &#91;"Banana", "Cherry"]</code></pre>



<h2 class="wp-block-heading">06. Array unshift()</h2>



<p>The <code>unshift()</code> method adds one or more elements to the beginning of an array and returns the new length of the array.</p>



<pre class="wp-block-code"><code>let fruits = &#91;'Banana', 'Cherry'];
console.log(fruits.unshift('Apple')); // Outputs: 3
console.log(fruits); // Outputs: &#91;"Apple", "Banana", "Cherry"]</code></pre>



<h2 class="wp-block-heading">07. Array join()</h2>



<p>The <code>join()</code> method merges all the elements of an array into a string. The elements are separated by a specified separator. If no separator is mentioned, the elements are separated by a comma.</p>



<pre class="wp-block-code"><code>let fruits = &#91;'Apple', 'Banana', 'Cherry'];
console.log(fruits.join()); // Outputs: "Apple,Banana,Cherry"
console.log(fruits.join(' and ')); // Outputs: "Apple and Banana and Cherry"</code></pre>



<h2 class="wp-block-heading">08. Array delete</h2>



<p>In JavaScript, we can delete an element from an array using the <code>delete</code> keyword. However, it leaves undefined holes in the array.</p>



<pre class="wp-block-code"><code>let fruits = &#91;'Apple', 'Banana', 'Cherry'];
delete fruits&#91;1];
console.log(fruits); // Outputs: &#91;"Apple", undefined, "Cherry"]</code></pre>



<h2 class="wp-block-heading">09. Array concat()</h2>



<p>The <code>concat()</code> method merges two or more arrays and returns a new array. The original arrays are not</p>



<p>changed.</p>



<pre class="wp-block-code"><code>let fruits = &#91;'Apple', 'Banana'];
let moreFruits = &#91;'Cherry', 'Date'];
let allFruits = fruits.concat(moreFruits);
console.log(allFruits); // Outputs: &#91;"Apple", "Banana", "Cherry", "Date"]</code></pre>



<h2 class="wp-block-heading">10. Array flat()</h2>



<p>The <code>flat()</code> method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.</p>



<pre class="wp-block-code"><code>let nestedArray = &#91;1, 2, &#91;3, 4, &#91;5, 6]]];
console.log(nestedArray.flat(2)); // Outputs: &#91;1, 2, 3, 4, 5, 6]</code></pre>



<h2 class="wp-block-heading">11. Array splice()</h2>



<p>The <code>splice()</code> method adds or removes items from an array. The first argument specifies the array position for insertion or deletion. The second argument specifies the number of elements to delete. The subsequent arguments are the new elements to be added.</p>



<pre class="wp-block-code"><code>let fruits = &#91;'Apple', 'Banana', 'Cherry'];
fruits.splice(1, 1, 'Blackberry');
console.log(fruits); // Outputs: &#91;"Apple", "Blackberry", "Cherry"]</code></pre>



<h2 class="wp-block-heading">12. Array slice()</h2>



<p>The <code>slice()</code> method returns a shallow copy of a portion of an array into a new array object. The original array will not be modified.</p>



<pre class="wp-block-code"><code>let fruits = &#91;'Apple', 'Banana', 'Cherry', 'Date'];
let someFruits = fruits.slice(1, 3);
console.log(someFruits); // Outputs: &#91;"Banana", "Cherry"]</code></pre>



<h2 class="wp-block-heading">13. Array map()</h2>



<p>The <code>map()</code> method creates a new array by calling a function for every array element. The original array is not changed.</p>



<pre class="wp-block-code"><code>let numbers = &#91;1, 2, 3, 4];
let squares = numbers.map(num =&gt; num * num);
console.log(squares); // Outputs: &#91;1, 4, 9, 16]</code></pre>



<p>Absolutely, let&#8217;s look at a few more useful array methods that JavaScript provides:</p>



<h2 class="wp-block-heading">14. Array.filter()</h2>



<p>The <code>filter()</code> method creates a new array with all elements that pass the test implemented by the provided function.</p>



<pre class="wp-block-code"><code>let numbers = &#91;1, 2, 3, 4, 5];
let evens = numbers.filter(num =&gt; num % 2 === 0);
console.log(evens);  // Outputs: &#91;2, 4]</code></pre>



<h2 class="wp-block-heading">15. Array.reduce()</h2>



<p>The <code>reduce()</code> method applies a function against an accumulator and each element in the array (from left to right) to reduce it to a single value.</p>



<pre class="wp-block-code"><code>let numbers = &#91;1, 2, 3, 4, 5];
let sum = numbers.reduce((total, num) =&gt; total + num, 0);
console.log(sum);  // Outputs: 15</code></pre>



<h2 class="wp-block-heading">16. Array.every()</h2>



<p>The <code>every()</code> method tests whether all elements in the array pass the test implemented by the provided function.</p>



<pre class="wp-block-code"><code>let numbers = &#91;2, 4, 6];
let allEven = numbers.every(num =&gt; num % 2 === 0);
console.log(allEven);  // Outputs: true</code></pre>



<h2 class="wp-block-heading">17. Array.some()</h2>



<p>The <code>some()</code> method tests whether at least one element in the array passes the test implemented by the provided function.</p>



<pre class="wp-block-code"><code>let numbers = &#91;1, 3, 5, 6];
let hasEven = numbers.some(num =&gt; num % 2 === 0);
console.log(hasEven);  // Outputs: true</code></pre>



<h2 class="wp-block-heading">18. Array.find()</h2>



<p>The <code>find()</code> method returns the value of the first element in the array that satisfies the provided testing function.</p>



<pre class="wp-block-code"><code>let numbers = &#91;5, 12, 8, 130, 44];
let found = numbers.find(element =&gt; element &gt; 10);
console.log(found); // Outputs: 12</code></pre>



<h2 class="wp-block-heading">19. Array.findIndex()</h2>



<p>The <code>findIndex()</code> method returns the index of the first element in the array that satisfies the provided testing function.</p>



<pre class="wp-block-code"><code>let numbers = &#91;5, 12, 8, 130, 44];
let foundIndex = numbers.findIndex(element =&gt; element &gt; 10);
console.log(foundIndex); // Outputs: 1</code></pre>



<h2 class="wp-block-heading">20. Array.reverse()</h2>



<p>The <code>reverse()</code> method reverses an array in place. The first array element becomes the last, and the last array element becomes the first.</p>



<pre class="wp-block-code"><code>let array = &#91;'one', 'two', 'three'];
console.log(array.reverse()); // Outputs: &#91;"three", "two", "one"]</code></pre>



<p>My apologies for the oversight. Let&#8217;s explore the <code>sort()</code> method.</p>



<h2 class="wp-block-heading">21. Array.sort()</h2>



<p>The <code>sort()</code> method sorts the elements of an array in place and returns the array. The sort is not necessarily stable, and the default sort order is according to string Unicode code points.</p>



<pre class="wp-block-code"><code>let numbers = &#91;5, 1, 10, 3];
console.log(numbers.sort());  // Outputs: &#91;1, 10, 3, 5]

let fruits = &#91;"Banana", "Orange", "Apple", "Cherry"];
console.log(fruits.sort());  // Outputs: &#91;"Apple", "Banana", "Cherry", "Orange"]</code></pre>



<p>By default, <code>sort()</code> converts elements to strings for comparison, which is why <code>[1, 10, 3, 5]</code> gets sorted incorrectly. We can pass in a comparison function to sort numeric arrays correctly:</p>



<pre class="wp-block-code"><code>let numbers = &#91;5, 1, 10, 3];
console.log(numbers.sort((a, b) =&gt; a - b));  // Outputs: &#91;1, 3, 5, 10]</code></pre>



<p>In this case, <code>(a, b) =&gt; a - b</code> is a comparison function that subtracts <code>b</code> from <code>a</code>. The function basically says that if <code>a</code> is less than <code>b</code>, make <code>a</code> come before <code>b</code>. If <code>a</code> is greater than <code>b</code>, make <code>a</code> come after <code>b</code>. And if <code>a</code> and <code>b</code> are equal, leave them unchanged with respect to each other.</p>



<p>The <code>sort()</code> method can be a powerful tool when used correctly in your JavaScript code.</p>



<p>Yes, JavaScript indeed provides several more Array methods. Let&#8217;s take a look at a few additional ones:</p>



<h2 class="wp-block-heading">22. Array.fill()</h2>



<p>The <code>fill()</code> method changes all elements in an array to a static value, from a start index (default 0) to an end index (default array.length).</p>



<pre class="wp-block-code"><code>let numbers = &#91;1, 2, 3, 4, 5];
console.log(numbers.fill(0, 2, 4));  // Outputs: &#91;1, 2, 0, 0, 5]</code></pre>



<h2 class="wp-block-heading">23. Array.includes()</h2>



<p>The <code>includes()</code> method determines whether an array includes a certain value among its entries, returning true or false as appropriate.</p>



<pre class="wp-block-code"><code>let numbers = &#91;1, 2, 3, 4, 5];
console.log(numbers.includes(3));  // Outputs: true
console.log(numbers.includes(6));  // Outputs: false</code></pre>



<h2 class="wp-block-heading">24. Array.indexOf()</h2>



<p>The <code>indexOf()</code> method returns the first index at which a given element can be found in the array, or -1 if it is not present.</p>



<pre class="wp-block-code"><code>let fruits = &#91;"Apple", "Banana", "Cherry"];
console.log(fruits.indexOf("Banana"));  // Outputs: 1</code></pre>



<h2 class="wp-block-heading">25. Array.lastIndexOf()</h2>



<p>The <code>lastIndexOf()</code> method returns the last index at which a given element can be found in the array, or -1 if it is not present. The array is searched backwards, starting at fromIndex.</p>



<pre class="wp-block-code"><code>let numbers = &#91;1, 2, 3, 2, 4];
console.log(numbers.lastIndexOf(2));  // Outputs: 3</code></pre>



<h2 class="wp-block-heading">26. Array.forEach()</h2>



<p>The <code>forEach()</code> method executes a provided function once for each array element.</p>



<pre class="wp-block-code"><code>let numbers = &#91;1, 2, 3, 4, 5];
numbers.forEach((value, index, array) =&gt; {
  console.log(value);  // Outputs each number
});</code></pre>



<h2 class="wp-block-heading">27. Array.from()</h2>



<p>The <code>Array.from()</code> static method creates a new, shallow-copied array instance from an array-like or iterable object.</p>



<pre class="wp-block-code"><code>console.log(Array.from('Hello'));  // Outputs: &#91;'H', 'e', 'l', 'l', 'o']</code></pre>



<h2 class="wp-block-heading">28. Array.isArray()</h2>



<p>The <code>Array.isArray()</code> method determines whether the passed value is an Array.</p>



<pre class="wp-block-code"><code>console.log(Array.isArray(&#91;1, 2, 3]));  // Outputs: true
console.log(Array.isArray({foo: 123})); // Outputs: false</code></pre>



<p>Indeed, there are even more array methods to explore. Here are a few more:</p>



<h2 class="wp-block-heading">29. Array.find()</h2>



<p>The <code>find()</code> method returns the value of the first element in the provided array that satisfies the provided testing function.</p>



<pre class="wp-block-code"><code>let numbers = &#91;5, 12, 8, 130, 44];
let found = numbers.find(num =&gt; num &gt; 10);
console.log(found);  // Outputs: 12</code></pre>



<h2 class="wp-block-heading">30. Array.flatmap()</h2>



<p>The <code>flatMap()</code> method first maps each element using a mapping function, then flattens the result into a new array. It&#8217;s essentially equivalent to a <code>map()</code> followed by a <code>flat()</code> of depth 1.</p>



<pre class="wp-block-code"><code>let arr = &#91;1, 2, 3, 4];
let newArr = arr.flatMap(x =&gt; &#91;x, x * 2]);
console.log(newArr);  // Outputs: &#91;1, 2, 2, 4, 3, 6, 4, 8]</code></pre>



<h2 class="wp-block-heading">31. Array.keys()</h2>



<p>The <code>keys()</code> method returns a new Array Iterator object that contains the keys for each index in the array.</p>



<pre class="wp-block-code"><code>let arr = &#91;'a', 'b', 'c'];
let iterator = arr.keys();
for (let key of iterator) {
    console.log(key);  // Outputs: 0, then 1, then 2
}</code></pre>



<h2 class="wp-block-heading">32. Array.values()</h2>



<p>The <code>values()</code> method returns a new Array Iterator object that contains the values for each index in the array.</p>



<pre class="wp-block-code"><code>let arr = &#91;'a', 'b', 'c'];
let iterator = arr.values();
for (let value of iterator) {
    console.log(value);  // Outputs: 'a', then 'b', then 'c'
}</code></pre>



<h2 class="wp-block-heading">33. Array.entries()</h2>



<p>The <code>entries()</code> method returns a new Array Iterator object that contains the key/value pairs for each index in the array.</p>



<pre class="wp-block-code"><code>let arr = &#91;'a', 'b', 'c'];
let iterator = arr.entries();
for (let pair of iterator) {
    console.log(pair);  // Outputs: &#91;0, 'a'], then &#91;1, 'b'], then &#91;2, 'c']
}</code></pre>



<h2 class="wp-block-heading">34. Array.copyWithin()</h2>



<p>The <code>copyWithin()</code> method shallow copies part of an array to another location in the same array and returns it without modifying its length.</p>



<pre class="wp-block-code"><code>let arr = &#91;'a', 'b', 'c', 'd', 'e'];
console.log(arr.copyWithin(0, 3, 4));  // Outputs: &#91;'d', 'b', 'c', 'd', 'e']</code></pre>



<h2 class="wp-block-heading">35. Array.toLocaleString()</h2>



<p>The <code>toLocaleString()</code> method returns a string representing the elements of the array. The elements are converted to Strings using their <code>toLocaleString</code> methods and these Strings are separated by a locale-specific String (such as a comma “,”).</p>



<pre class="wp-block-code"><code>let arr = &#91;1000, 'Banana', new Date()];
console.log(arr.toLocaleString());  // Example Output: "1,000,Banana,12/11/2023, 7:00:00 PM"</code></pre>



<p>Sure, let&#8217;s go over a few more methods that are less commonly used but can still be useful in certain scenarios:</p>



<h2 class="wp-block-heading">36. Array.at()</h2>



<p>The <code>at()</code> method takes an integer value and returns the item at that index, allowing for positive and negative integers. Negative integers count back from the last item in the array.</p>



<pre class="wp-block-code"><code>let arr = &#91;'a', 'b', 'c', 'd', 'e'];
console.log(arr.at(-1)); // Outputs: 'e'</code></pre>



<h2 class="wp-block-heading">37. Array.reduceRight()</h2>



<p>The <code>reduceRight()</code> method applies a function against an accumulator and each element in the array (from right to left) to reduce it to a single value. This is essentially like the <code>reduce()</code> method, but it goes from right to left.</p>



<pre class="wp-block-code"><code>let array1 = &#91;&#91;0, 1], &#91;2, 3], &#91;4, 5]].reduceRight((accumulator, currentValue) =&gt; accumulator.concat(currentValue));
console.log(array1);  // Outputs: &#91;4, 5, 2, 3, 0, 1]</code></pre>



<h2 class="wp-block-heading">38. Array.toSource() (Non-standard)</h2>



<p>The <code>toSource()</code> method returns a string representing the source code of the array. This is a non-standard feature and it&#8217;s not supported in all environments.</p>



<pre class="wp-block-code"><code>let arr = &#91;'a', 'b', 'c', 'd', 'e'];
console.log(arr.toSource()); // Outputs: &#91;'a', 'b', 'c', 'd', 'e'] (in Firefox)</code></pre>



<p>These are some of the other methods provided by the Array object. Remember, not all methods are universally supported (like <code>toSource()</code>) and some are very new (like <code>at()</code>), so always consider the environments where your code will run.</p>



<p>These methods provide even more ways to interact with and manipulate arrays in JavaScript. Remember, using these methods efficiently can help you write cleaner and more concise code.</p>



<p>Understanding and using these methods will give you a powerful toolset to work with arrays in JavaScript. Remember, it&#8217;s not just about knowing the methods but also understanding when and where to use them.</p>



<p>Happy coding!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://snehaltayde.com/javascript-array-methods/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">694</post-id>	</item>
		<item>
		<title>5 Must Use Plugins When Working On A WordPress Site</title>
		<link>https://snehaltayde.com/5-must-use-plugins-when-working-on-a-wordpress-site/</link>
					<comments>https://snehaltayde.com/5-must-use-plugins-when-working-on-a-wordpress-site/#respond</comments>
		
		<dc:creator><![CDATA[Snehalkumar]]></dc:creator>
		<pubDate>Sun, 17 May 2020 06:57:24 +0000</pubDate>
				<category><![CDATA[code]]></category>
		<category><![CDATA[wordpress]]></category>
		<guid isPermaLink="false">https://snehaltayde.com/?p=570</guid>

					<description><![CDATA[So here are 5 Plugins I always use in my development workflow, and I think you should give them a try.]]></description>
										<content:encoded><![CDATA[
<p>I have been working on wordpress from years now and gone are the days when I used build wordpress websites locally on a xamp servers and then migrate them to staging or production.</p>



<p>Now I just create a lightSail Trial instance and start my WordPress development then and there, the good thing about it is I have root access to use WordPress CLI as well as its more straightforward to scale, migrate to production or to share a staging link with the client.</p>



<p>So here are 5 Plugins I always use in my development workflow, and I think you should give them a try. </p>



<p><strong>1: File Manager</strong></p>



<figure class="wp-block-image size-large"><a href="https://wordpress.org/plugins/wp-file-manager/"><img data-recalc-dims="1" fetchpriority="high" decoding="async" width="845" height="400" src="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-7.png?resize=845%2C400" alt="" class="wp-image-589" srcset="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-7.png?w=976&amp;ssl=1 976w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-7.png?resize=570%2C270&amp;ssl=1 570w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-7.png?resize=160%2C76&amp;ssl=1 160w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-7.png?resize=768%2C364&amp;ssl=1 768w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-7.png?resize=845%2C400&amp;ssl=1 845w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-7.png?resize=585%2C277&amp;ssl=1 585w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-7.png?resize=520%2C246&amp;ssl=1 520w" sizes="(max-width: 845px) 100vw, 845px" /></a></figure>



<p>File Manager plugin allows you to edit, delete, upload, download, zip, copy and paste files and folders directly from the WordPress backend. You don’t have to bother with FTP to manage and move your files from location to location. I usually<br>Use this plugin to upload plugins or themes manually, or modify the folder structure and creating zip, and I don’t use this to edit or modify my files, I use another plugin for that.</p>



<p><strong>2: Theme Editor</strong></p>



<figure class="wp-block-image size-large"><a href="https://wordpress.org/plugins/theme-editor/"><img data-recalc-dims="1" decoding="async" width="845" height="366" src="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-8.png?resize=845%2C366" alt="" class="wp-image-591" srcset="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-8.png?w=942&amp;ssl=1 942w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-8.png?resize=570%2C247&amp;ssl=1 570w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-8.png?resize=160%2C69&amp;ssl=1 160w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-8.png?resize=768%2C333&amp;ssl=1 768w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-8.png?resize=845%2C366&amp;ssl=1 845w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-8.png?resize=585%2C253&amp;ssl=1 585w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-8.png?resize=520%2C225&amp;ssl=1 520w" sizes="(max-width: 845px) 100vw, 845px" /></a></figure>



<p>Theme editor allows you to edit theme files, create folders, upload files and remove any files and folders in themes plugins. You can easily customise your themes and plugins directly using this. This plugin is somewhat similar to the WP file manager plugin. Still, the critical difference is Theme editor triumphs in editing files by providing syntax highlighter, query selector. In contrast, WP File Manager is great for managing files and folders throughout your WordPress directory.</p>



<p><strong>3: Query Monitor</strong></p>



<figure class="wp-block-image size-large"><a href="https://wordpress.org/plugins/query-monitor/"><img data-recalc-dims="1" decoding="async" width="845" height="379" src="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-9.png?resize=845%2C379" alt="" class="wp-image-593" srcset="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-9.png?w=943&amp;ssl=1 943w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-9.png?resize=570%2C256&amp;ssl=1 570w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-9.png?resize=160%2C72&amp;ssl=1 160w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-9.png?resize=768%2C345&amp;ssl=1 768w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-9.png?resize=845%2C379&amp;ssl=1 845w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-9.png?resize=585%2C262&amp;ssl=1 585w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-9.png?resize=520%2C233&amp;ssl=1 520w" sizes="(max-width: 845px) 100vw, 845px" /></a></figure>



<p>Query Monitor is the developer tools panel for WordPress. It enables debugging of database queries, PHP errors, hooks and actions, block editor blocks, enqueued scripts and stylesheets, HTTP API calls, and more.</p>



<p>It includes some advanced features such as debugging of Ajax calls, REST API calls, and user capability checks. It consists of the ability to narrow down much of its output by plugin or theme, allowing you to determine poorly performing plugins, themes, or functions quickly.</p>



<p><strong>4: Classic Editor</strong></p>



<figure class="wp-block-image size-large"><a href="https://wordpress.org/plugins/classic-editor/"><img data-recalc-dims="1" loading="lazy" decoding="async" width="845" height="399" src="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-10.png?resize=845%2C399" alt="" class="wp-image-595" srcset="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-10.png?w=943&amp;ssl=1 943w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-10.png?resize=570%2C269&amp;ssl=1 570w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-10.png?resize=160%2C76&amp;ssl=1 160w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-10.png?resize=768%2C362&amp;ssl=1 768w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-10.png?resize=845%2C399&amp;ssl=1 845w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-10.png?resize=585%2C276&amp;ssl=1 585w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-10.png?resize=520%2C245&amp;ssl=1 520w" sizes="auto, (max-width: 845px) 100vw, 845px" /></a></figure>



<p>Let’s get this clear, not all of us like Gutenberg block editor, it is excellent, but it should not be forced down our throat. Here comes Classic Editor for our rescue, Classic Editor is an official plugin maintained by the WordPress team that restores the previous (“classic”) WordPress editor and the “Edit Post” screen. It makes it possible to use plugins that extend that screen, add old-style meta boxes, or otherwise depend on the previous editor. </p>



<p><strong>5: Duplicate Menu</strong></p>



<figure class="wp-block-image size-large"><a href="https://wordpress.org/plugins/duplicate-menu/"><img data-recalc-dims="1" loading="lazy" decoding="async" width="845" height="165" src="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-11.png?resize=845%2C165" alt="" class="wp-image-598" srcset="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-11.png?w=965&amp;ssl=1 965w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-11.png?resize=570%2C112&amp;ssl=1 570w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-11.png?resize=160%2C31&amp;ssl=1 160w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-11.png?resize=768%2C150&amp;ssl=1 768w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-11.png?resize=845%2C165&amp;ssl=1 845w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-11.png?resize=585%2C115&amp;ssl=1 585w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-11.png?resize=520%2C102&amp;ssl=1 520w" sizes="auto, (max-width: 845px) 100vw, 845px" /></a></figure>



<p>Have you ever worked on a website where there are 100s of the menu element, and you have neatly created a mega menu to fit all those menu elements? When you ask the client for feedback, he wants to see a few more variations in the menu structure, now creating a menu with 100s of menu elements again will be painful.</p>



<p>Duplicate Menu will allow you to create a second (or third, or fourth, etc.) copy of an existing Menu to do with what you will. It generates the clone on a programmatic level and recreates all necessary relationships to ensure the structure is retained as well.</p>



<p>So that’s it guys, here are my five must use plugins while working on a WordPress website, also these are mostly for the development environment, you can remove it on your production site.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://snehaltayde.com/5-must-use-plugins-when-working-on-a-wordpress-site/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">570</post-id>	</item>
		<item>
		<title>RESTRICT SHIPPING BASED ON  PINCODE IN SHOPIFY WITHOUT USING ANY APP</title>
		<link>https://snehaltayde.com/restrict-shipping-based-on-pincode-in-shopify-without-using-any-app/</link>
					<comments>https://snehaltayde.com/restrict-shipping-based-on-pincode-in-shopify-without-using-any-app/#respond</comments>
		
		<dc:creator><![CDATA[Snehalkumar]]></dc:creator>
		<pubDate>Wed, 06 May 2020 21:53:34 +0000</pubDate>
				<category><![CDATA[code]]></category>
		<guid isPermaLink="false">https://snehaltayde.com/?p=562</guid>

					<description><![CDATA[So this happened last weekend, I got a call from my client and he wanted me to restrict shipping only for specific Pin Codes for his Shopify store and he wanted that functionality in short period of time.]]></description>
										<content:encoded><![CDATA[
<p>So this happened last weekend, I got a call from my client and he wanted me to restrict shipping only for specific Pin Codes for his Shopify store and he wanted that functionality in short period of time. </p>



<p>See firstly I am a Woocommerce Guy, and if it was WooCommerce, I could just use the default Shipping Zone feature to restrict pin codes. But this was not Woocommerce, and there was no default way to limit shipping for specific pin codes in Shopify. </p>



<p>As time frame was limited, I tried first to check if I can find any Apps, and to my surprise, all the apps I found were substandard.</p>



<p>So I looked at the checkout page&#8217;s dom and decided to use client-side restriction using JavaScript. I must confess JavaScript is a lifesaver.</p>



<p>So let&#8217;s begin, I will show you what exactly I have done to achieve the goal of restricting shipping to specific pin-codes on Shopify. Also one more thing for this to work you will need access to your checkout page, which Requires Shopify Plus.</p>



<p>I am assuming that you know little bit about Shopify and are able to navigate to specific sections.</p>



<p><strong>Step 1: </strong>Creating a Js file in Assets folder to store all your pin codes in an array.</p>



<p>So first things first Lets create a blank JS file in your themes Assets folder and name it allpincodes.js (you can name it anything). </p>



<figure class="wp-block-image size-large"><img data-recalc-dims="1" loading="lazy" decoding="async" width="845" height="361" src="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image.png?resize=845%2C361" alt="" class="wp-image-535" srcset="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image.png?w=1049&amp;ssl=1 1049w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image.png?resize=570%2C243&amp;ssl=1 570w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image.png?resize=160%2C68&amp;ssl=1 160w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image.png?resize=768%2C328&amp;ssl=1 768w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image.png?resize=845%2C361&amp;ssl=1 845w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image.png?resize=585%2C250&amp;ssl=1 585w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image.png?resize=520%2C222&amp;ssl=1 520w" sizes="auto, (max-width: 845px) 100vw, 845px" /></figure>



<p><strong>Step 2: </strong>Create an Array with your pincodes in Your newly Created allpincodes.js file.</p>



<p>So once you have created the allpincodes.js file, lets create a javascript array to store your pincodes.</p>



<figure class="wp-block-image size-large"><img data-recalc-dims="1" loading="lazy" decoding="async" width="845" height="480" src="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-1.png?resize=845%2C480" alt="" class="wp-image-537" srcset="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-1.png?w=850&amp;ssl=1 850w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-1.png?resize=570%2C324&amp;ssl=1 570w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-1.png?resize=160%2C91&amp;ssl=1 160w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-1.png?resize=768%2C436&amp;ssl=1 768w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-1.png?resize=845%2C480&amp;ssl=1 845w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-1.png?resize=585%2C332&amp;ssl=1 585w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-1.png?resize=520%2C295&amp;ssl=1 520w" sizes="auto, (max-width: 845px) 100vw, 845px" /></figure>



<p>once this is done, lets go to our checkout.liquid template and include this javascript.</p>



<figure class="wp-block-image size-large"><img data-recalc-dims="1" loading="lazy" decoding="async" width="845" height="616" src="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-2-1001x730.png?resize=845%2C616" alt="" class="wp-image-542" srcset="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-2.png?resize=1001%2C730&amp;ssl=1 1001w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-2.png?resize=562%2C410&amp;ssl=1 562w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-2.png?resize=160%2C117&amp;ssl=1 160w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-2.png?resize=768%2C560&amp;ssl=1 768w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-2.png?resize=754%2C550&amp;ssl=1 754w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-2.png?resize=585%2C427&amp;ssl=1 585w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-2.png?resize=520%2C379&amp;ssl=1 520w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-2.png?resize=829%2C605&amp;ssl=1 829w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-2.png?resize=891%2C650&amp;ssl=1 891w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-2.png?w=1028&amp;ssl=1 1028w" sizes="auto, (max-width: 845px) 100vw, 845px" /><figcaption>&lt;script src=&#8221;{{&#8216;allpincodes.js&#8217; | asset_url}}&#8221; &gt; &lt;/script&gt;</figcaption></figure>



<p>So once you have included the Javascript file in checkout.liquid template now you have access to the pin codes array from allpincodes.js</p>







<p><strong>Step 3:</strong>  Get pin code entered by user on Shopify checkout page </p>



<figure class="wp-block-image size-full"><img data-recalc-dims="1" loading="lazy" decoding="async" width="845" height="476" src="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-4.png?resize=845%2C476" alt="" class="wp-image-549" srcset="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-4.png?w=1375&amp;ssl=1 1375w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-4.png?resize=570%2C321&amp;ssl=1 570w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-4.png?resize=1170%2C659&amp;ssl=1 1170w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-4.png?resize=160%2C90&amp;ssl=1 160w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-4.png?resize=768%2C432&amp;ssl=1 768w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-4.png?resize=845%2C476&amp;ssl=1 845w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-4.png?resize=585%2C329&amp;ssl=1 585w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-4.png?resize=520%2C293&amp;ssl=1 520w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-4.png?resize=1075%2C605&amp;ssl=1 1075w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-4.png?resize=1155%2C650&amp;ssl=1 1155w" sizes="auto, (max-width: 845px) 100vw, 845px" /></figure>



<p>So first of all let&#8217;s create a Script tag in checkout.liquid file, and create a  Jquery Document ready function </p>



<p>$(document).ready(function(){<br>//Your Code here<br>});</p>



<p>We are using this function because we want our code to run once the dom is loaded.</p>



<pre class="wp-block-code"><code>jQuery(".step__footer__continue-btn").click(function(){

    var pincode = jQuery('.field__input-wrapper input&#91;name="checkout&#91;shipping_address]&#91;zip]"]').val();

    document.cookie = 'pincode' + "=" + pincode ;

    });

    const newpincode =  getCookie("pincode");</code></pre>



<p>So as you can see the code above is in the Code Block 1 in Image. And in this code we are using a Click event listener on Continue To Shoping Button in the Checkout page.</p>



<figure class="wp-block-image size-large"><img data-recalc-dims="1" loading="lazy" decoding="async" width="845" height="721" src="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-5-856x730.png?resize=845%2C721" alt="" class="wp-image-552" srcset="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-5.png?resize=856%2C730&amp;ssl=1 856w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-5.png?resize=481%2C410&amp;ssl=1 481w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-5.png?resize=160%2C136&amp;ssl=1 160w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-5.png?resize=768%2C655&amp;ssl=1 768w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-5.png?resize=645%2C550&amp;ssl=1 645w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-5.png?resize=585%2C499&amp;ssl=1 585w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-5.png?resize=710%2C605&amp;ssl=1 710w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-5.png?resize=763%2C650&amp;ssl=1 763w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-5.png?w=908&amp;ssl=1 908w" sizes="auto, (max-width: 845px) 100vw, 845px" /></figure>



<p>The Event listener is checking for the User inputted Pin code and storing it into a cookie named pincode.</p>



<p>And Outside of the event listener, we are getting the pincode cookie value and storing it into a newpincode variable.</p>



<p><strong>Step 4:</strong> Check if user submitted pincode is available in pincodes array.</p>



<pre class="wp-block-code"><code>       var checkpincodes = pincodes.filter(function(item) {
          if(item === parseInt(newpincode)){

           return item;

          }});

          const filteredpincode = checkpincodes&#91;0];</code></pre>



<p>So as we have access to our pincodes array from allpincodes.js file which we created in Assets folder and later included into Checkout.liquid file. </p>



<p>We can use the filter method on our array. The filter() method creates an array filled with all array elements that pass a test, in our case, it will only return 1 value in our array if it passed the if statement else it will return undefined.</p>



<p>So in the above code snippet inside our checkincodes method, we are checking if the Pincode from our array is equal to the newpincode which user inputted. if it&#8217;s true it will return that particular Pincode, we can also simply return true and use that for our conditional statement, but I want to return entire Pincode for now.</p>



<p>If the Pincode user-inputted matched with the Pincode from our pincodes array, we will have access to that Pincode at checkpincodes[0]. Later we created another constant called filteredpincode and assigned checkpincodes[0] to it.</p>







<p>Step 5: Once again check and matched the pincodes and take actions.</p>



<pre class="wp-block-code"><code>        if(filteredpincode == newpincode){
          console.log('All good, Nothing to do here')

        }

          else{

          setTimeout(function(){ 

            jQuery("#continue_button").css("display", "none");

              jQuery("&lt;span>Sorry We Do Not Deliver To Your PinCode!&lt;/span>").insertBefore(".section--shipping-method");
          }, 1000);



        }</code></pre>



<p>So you must be wondering why we are checking this again? you are right we could check the pincode and take actions right there in our array filter method, but I wanted to keep the conditional separate from that statement, it&#8217;s all preference.</p>



<p>So in above code we have an if and else code block. In here we are checking that if the filteredpincode is equal to the pincode user inputted, then do nothing, and just console log  a message.</p>



<figure class="wp-block-image size-large"><img data-recalc-dims="1" loading="lazy" decoding="async" width="845" height="299" src="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-6.png?resize=845%2C299" alt="" class="wp-image-557" srcset="https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-6.png?w=963&amp;ssl=1 963w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-6.png?resize=570%2C202&amp;ssl=1 570w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-6.png?resize=160%2C57&amp;ssl=1 160w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-6.png?resize=768%2C272&amp;ssl=1 768w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-6.png?resize=845%2C299&amp;ssl=1 845w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-6.png?resize=585%2C207&amp;ssl=1 585w, https://i0.wp.com/snehaltayde.com/wp-content/uploads/2020/05/image-6.png?resize=520%2C184&amp;ssl=1 520w" sizes="auto, (max-width: 845px) 100vw, 845px" /></figure>



<p>But in case it doesn&#8217;t match and filteredpincode is undefined we have used a setTimeout Function and after 1 second we disable the continue Shopping button and add a message &#8220;Sorry We Do Not Deliver To Your PinCode!&#8221; on the shipping page and restrict the user from making a purchase.</p>



<p>Thats it Guys, if you have any questions do comment below, I will definitely help you out.</p>




]]></content:encoded>
					
					<wfw:commentRss>https://snehaltayde.com/restrict-shipping-based-on-pincode-in-shopify-without-using-any-app/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">562</post-id>	</item>
	</channel>
</rss>
