<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QoDesign]]></title><description><![CDATA[Crafting Your Business Solutions]]></description><link>https://blog.qodesign.net</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1679845603450/vN_77hwmI.png</url><title>QoDesign</title><link>https://blog.qodesign.net</link></image><generator>RSS for Node</generator><lastBuildDate>Tue, 10 Nov 2026 14:36:17 GMT</lastBuildDate><atom:link href="https://blog.qodesign.net/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Push associative array into array in JavaScript]]></title><description><![CDATA[In this example, we declare an empty array called myArray and a function called insert that takes two parameters: key and value. Inside the insert…]]></description><link>https://blog.qodesign.net/push-associative-array-into-array-in-javascript</link><guid isPermaLink="true">https://blog.qodesign.net/push-associative-array-into-array-in-javascript</guid><category><![CDATA[js]]></category><category><![CDATA[associative arrays]]></category><category><![CDATA[jQuery]]></category><dc:creator><![CDATA[Rk Mahbub]]></dc:creator><pubDate>Mon, 27 Mar 2023 13:24:51 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1679923735980/f338c3eb-f369-4516-b40a-82f69c1ac0e0.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> myArray = [];

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">insert</span>(<span class="hljs-params">key, value</span>) </span>{
  <span class="hljs-keyword">let</span> obj = {};
  obj[key] = value;
  myArray.push(obj);
}

insert(<span class="hljs-string">"name"</span>, <span class="hljs-string">"John"</span>);
insert(<span class="hljs-string">"age"</span>, <span class="hljs-number">30</span>);
insert(<span class="hljs-string">"city"</span>, <span class="hljs-string">"New York"</span>);

<span class="hljs-built_in">console</span>.log(myArray);
</code></pre>
<p>In this example, we declare an empty array called <code>myArray</code> and a function called <code>insert</code> that takes two parameters: <code>key</code> and <code>value</code>. Inside the <code>insert</code> function, we create an empty object called <code>obj</code>. We then use square bracket notation to set a property on <code>obj</code> with the name specified by the <code>key</code> parameter and the value specified by the <code>value</code> parameter.</p>
<p>For example, when we call <code>insert("name", "John")</code>, it sets the property <code>name</code> on <code>obj</code> with the value <code>"John"</code>. Similarly, when we call <code>insert("age", 30)</code>, it sets the property <code>age</code> on <code>obj</code> with the value <code>30</code>.</p>
<p>Finally, we push <code>obj</code> into the <code>myArray</code> array, which now contains a list of objects with dynamically named properties.</p>
<p>Note that you can use any variable as the key parameter in the <code>insert</code> function, as long as it is a string or can be converted to a string. This allows you to dynamically set property names based on user input, API responses, or any other source of data.</p>
<hr />
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> myArray = [
  { <span class="hljs-attr">name</span>: <span class="hljs-string">"John"</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">30</span> },
  { <span class="hljs-attr">name</span>: <span class="hljs-string">"Jane"</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">25</span> },
  { <span class="hljs-attr">name</span>: <span class="hljs-string">"Bob"</span>, <span class="hljs-attr">age</span>: <span class="hljs-number">40</span> }
];

myArray.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">element, index</span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Element at index "</span> + index + <span class="hljs-string">":"</span>);
  <span class="hljs-built_in">Object</span>.keys(element).forEach(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">key</span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"  "</span> + key + <span class="hljs-string">": "</span> + element[key]);
  });
});
</code></pre>
<p>In this example, we declare an array called <code>myArray</code> that contains three objects, each with a <code>name</code> and <code>age</code> property. We then use the <code>forEach()</code> method to iterate over each element in <code>myArray</code>.</p>
<p>For each element, we use the <code>Object.keys()</code> method to get an array of all the keys (property names) in the object. We then use another <code>forEach()</code> method to iterate over each key and log both the key and value to the console.</p>
<p>The <code>element</code> parameter in the outer <code>forEach()</code> callback function represents the current element being processed, and the <code>index</code> parameter represents the index of the current element in the array. The inner <code>forEach()</code> callback function iterates over the keys of the current element, and the <code>key</code> parameter represents the current key being processed.</p>
<p>So for each element in the array, this code logs each key-value pair to the console like this:</p>
<pre><code class="lang-javascript">Element at index <span class="hljs-number">0</span>:
  name: John
  <span class="hljs-attr">age</span>: <span class="hljs-number">30</span>
Element at index <span class="hljs-number">1</span>:
  name: Jane
  <span class="hljs-attr">age</span>: <span class="hljs-number">25</span>
Element at index <span class="hljs-number">2</span>:
  name: Bob
  <span class="hljs-attr">age</span>: <span class="hljs-number">40</span>
</code></pre>
<hr />
<blockquote>
<p>You may Write the foreach in jquery instead of vanilla JavaScript</p>
</blockquote>
<p>In this example, we declare an array called <code>myArray</code> that contains three objects, each with a <code>name</code> and <code>age</code> property. We then use the <code>$.each()</code> function to iterate over each element in <code>myArray</code>.</p>
<p>For each element, we use the <code>$.each()</code> function again to iterate over each key-value pair in the object and log both the key and value to the console.</p>
<p>The <code>index</code> parameter in the outer <code>$.each()</code> callback function represents the index of the current element in the array, and the <code>element</code> parameter represents the current element being processed. The inner <code>$.each()</code> callback function iterates over the key-value pairs of the current element, and the <code>key</code> and <code>value</code> parameters represent the current key-value pair being processed.</p>
<p>So for each element in the array, this code logs each key-value pair to the console like this:</p>
<pre><code class="lang-javascript">$.each(myArray, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">index, element</span>) </span>{
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Element at index "</span> + index + <span class="hljs-string">":"</span>);
  $.each(element, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">key, value</span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"  "</span> + key + <span class="hljs-string">": "</span> + value);
  });
});
</code></pre>
<pre><code class="lang-javascript">Element at index <span class="hljs-number">0</span>:
  name: John
  <span class="hljs-attr">age</span>: <span class="hljs-number">30</span>
Element at index <span class="hljs-number">1</span>:
  name: Jane
  <span class="hljs-attr">age</span>: <span class="hljs-number">25</span>
Element at index <span class="hljs-number">2</span>:
  name: Bob
  <span class="hljs-attr">age</span>: <span class="hljs-number">40</span>
</code></pre>
<p>You can modify this code to suit your specific use case, such as performing some operation on each key-value pair instead of logging it to the console.</p>
]]></content:encoded></item><item><title><![CDATA[Laravel Validation is unique/exists with different database connection]]></title><description><![CDATA[Laravel Validation is unique/exists with different database connection]]></description><link>https://blog.qodesign.net/laravel-validation-is-uniqueexists-with-different-database-connection</link><guid isPermaLink="true">https://blog.qodesign.net/laravel-validation-is-uniqueexists-with-different-database-connection</guid><category><![CDATA[Laravel]]></category><category><![CDATA[Validation]]></category><dc:creator><![CDATA[Rk Mahbub]]></dc:creator><pubDate>Sun, 26 Mar 2023 16:10:23 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1679846651604/4997f96c-b2cb-47e8-9854-e587284b5517.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<pre><code class="lang-php"><span class="hljs-string">'email'</span> =&gt; <span class="hljs-string">'required|unique:mysql2.users'</span>
</code></pre>
<p>Where mysql2 is the second database settings array in the database.php file</p>
]]></content:encoded></item></channel></rss>