<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Nurain </title>
    <description>The latest articles on Forem by Nurain  (@adexbam).</description>
    <link>https://forem.com/adexbam</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1183658%2F0f50f61b-357c-4c3c-b495-0b23cddd93f5.jpg</url>
      <title>Forem: Nurain </title>
      <link>https://forem.com/adexbam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/adexbam"/>
    <language>en</language>
    <item>
      <title>10 JavaScript Array Methods That Will Make You Look Like a Pro</title>
      <dc:creator>Nurain </dc:creator>
      <pubDate>Mon, 11 Mar 2024 22:11:30 +0000</pubDate>
      <link>https://forem.com/adexbam/10-javascript-array-methods-that-will-make-you-look-like-a-pro-57dh</link>
      <guid>https://forem.com/adexbam/10-javascript-array-methods-that-will-make-you-look-like-a-pro-57dh</guid>
      <description>&lt;p&gt;&lt;strong&gt;Unlock Your JavaScript Potential: Master These 10 Array Methods&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Are you ready to take your JavaScript skills to the next level? Whether you're a seasoned developer or just starting your coding journey, mastering array methods is an essential step towards becoming a JavaScript pro.&lt;/p&gt;

&lt;p&gt;In this article, we'll explore 10 powerful array methods that will not only streamline your code but also elevate your programming prowess. From simplifying complex operations to unleashing the full potential of your data structures, these methods are the secret weapons of top-tier developers.&lt;/p&gt;

&lt;p&gt;So, let's dive into the world of JavaScript array methods and unleash your full programming potential!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. forEach() Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;forEach()&lt;/em&gt; method executes a given function on every element of an array. It does not return a new array but instead modifies the original array if your callback function changes any elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const register = [
    { name: "Bruce Shittu", yearOfReg: 2000 },
    { name: "Will Smart", yearOfReg: 1998 },
    { name: "Adex Popins", yearOfReg: 2001 },
    { name: "Nurain Bamidele", yearOfReg: 1992 },
    { name: "John Doe", yearOfReg: 2001 },
]

register.forEach(register =&amp;gt;
    console.log(`Mr. ${register.name} 
    register in year ${register.yearOfReg}`))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Mr. Bruce Shittu register in year 2000
Mr. Will Smart register in year 1998
Mr. Adex Popins register in year 2001
Mr. Nurain Bamidele register in year 1992
Mr. John Doe register in year 2001
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. map() Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;map()&lt;/em&gt; method creates a new array with the results of calling a provided function on every element in the original array. It's designed for transforming existing elements into new elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4, 5, 6, 7, 8];

const doubledNumbers = numbers.map((number) =&amp;gt; {
    return number * 2; // Apply the operation to each element
});

console.log(doubledNumbers);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[2,  4,  6,  8, 10, 12, 14, 16]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The map method creates a new array (doubledNumbers) with the transformed elements (doubled values).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. shift() Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;shift()&lt;/em&gt; method is used to remove the first element from an array and returns the removed element. It's a mutating method, meaning it modifies the original array. The remaining elements in the array are shifted down one position to fill the gap left by the removed element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fruits = ["Apple", "Banana", "Orange", "Mango", "Tangerine"];

const firstFruit = fruits.shift(); // firstFruit will be "Apple"
console.log(fruits);  // Output: ["Banana", "Orange", "Mango", "Tangerine"] (original array modified)
console.log(firstFruit); // Output: "Apple" (removed element)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ 'Banana', 'Orange', 'Mango', 'Tangerine' ]
Apple
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;shift()&lt;/em&gt; returns the value of the removed element. If the array is empty i.e length is 0, &lt;em&gt;shift()&lt;/em&gt; returns &lt;em&gt;undefined&lt;/em&gt;. Remember, &lt;em&gt;shift()&lt;/em&gt; alters the original array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. unshift() Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;unshift()&lt;/em&gt; method in JavaScript is the opposite of &lt;em&gt;shift()&lt;/em&gt;. It's used to add one or more elements to the beginning of an array and returns the new length of the array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const colors = ["red", "green", "blue", "violet"];

const newColors = colors.unshift("yellow", "purple"); 
console.log(colors);  
console.log(newColors); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ 'yellow', 'purple', 'red', 'green', 'blue', 'violet' ]
6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;unshift()&lt;/em&gt; takes any number of arguments, which are the elements you want to add to the array. These elements are inserted at the beginning of the array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. push() Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;push()&lt;/em&gt; method is a versatile tool for manipulating arrays. It allows you to add one or more elements to the end of an array and returns the new length of the array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4, 5];

const newNumbers = numbers.push(6, 7); 
console.log(numbers);
console.log(newNumbers); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[1, 2, 3, 4, 5, 6, 7]
7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;em&gt;push()&lt;/em&gt; takes any number of arguments, which represent the elements you want to add to the array. These elements are inserted at the end of the array. Also,  _push() _  modifies the original array in place and the length.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. pop() Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;pop()&lt;/em&gt; method is used to remove the last element from an array and return the removed element. It's a mutating method, meaning it modifies the original array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fruits = ["Apple", "Banana", "Orange", "Mango", "Tangerine"];

const removeFruit = fruits.pop();
console.log(fruits);  
console.log(removeFruit);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ 'Apple', 'Banana', 'Orange', 'Mango' ]
Tangerine
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;em&gt;pop()&lt;/em&gt; method targets the element at the last index (which is length - 1) in the array and removes it, decreasing the length accordingly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. join() Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The join() method in JavaScript is a powerful tool for combining the elements of an array into a single string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const colors = ["red", "green", "blue", "violet"];

const joinColors = colors.join(","); 
const joinColorsHyphen = colors.join(" - "); 

console.log(colors); 
console.log(joinColors); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ 'red', 'green', 'blue', 'violet' ]
red,green,blue,violet
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;em&gt;join()&lt;/em&gt; iterates through the elements of the array and joins them together, separated by a specified separator string (optional). If no separator is provided, the default separator is a comma (,). Each element in the array is converted to a string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. slice() Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;slice()&lt;/em&gt; method is for extracting a section of an array and returning it as a new array. It doesn't modify the original array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const countries = ["Panama", "USA", "Nigeria", "Ghana","Brazil"]

// Extracting everything from index 2 (inclusive) to the end
const restCountries = countries.slice(2); 
console.log(restCountries);

console.log(countries)
const subCountries = countries.slice(1, 3)
console.log(subCountries)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ 'Nigeria', 'Ghana', 'Brazil' ]
[ 'Panama', 'USA', 'Nigeria', 'Ghana', 'Brazil' ]
[ 'USA', 'Nigeria' ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;slice()&lt;/em&gt; takes two optional arguments, &lt;em&gt;startIndex&lt;/em&gt; and &lt;em&gt;endIndex&lt;/em&gt;, to specify the portion of the array to be extracted.&lt;br&gt;
_startIndex _(Default: 0): This argument defines the index from where the extraction should begin. Negative values are counted from the end of the array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;9. sort() Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The _sort() _method in JavaScript is used to sort the elements of an array in place.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [3, 1, 4, 1, 5, 9];

numbers.sort((a, b) =&amp;gt; a - b); // Sort numbers in ascending order
console.log(numbers);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ 1, 1, 3, 4, 5, 9 ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;sort()&lt;/em&gt; is a mutating method, meaning it modifies the original array in place.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;10. every() Method&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;every()&lt;/em&gt; method is a powerful tool for checking whether all elements in an array pass a test implemented by a provided function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numbers = [1, 2, 3, 4, 5];

// Checking if all numbers are even
const allEven = numbers.every(number =&amp;gt; number % 2 === 0); 
console.log(allEven); 

// Checking if all numbers are greater than 0
const allPositive = numbers.every(number =&amp;gt; number &amp;gt; 0); 
console.log(allPositive); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;false
true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;every()&lt;/em&gt; always return Boolean value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
This article explores 10 array methods in JavaScript programming, highlighting their potential to streamline tasks, manipulate data, and unlock the full potential of arrays in applications. By exploring these methods and experimenting, you can become a JavaScript array master.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Takeaways:&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;&lt;strong&gt;Array manipulation:&lt;/strong&gt;&lt;/em&gt; Methods like push(), pop(), shift(), and unshift() provide efficient ways to add, remove, and rearrange elements within arrays.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Iteration and transformation:&lt;/em&gt;&lt;/strong&gt; forEach() and map()empower you to process and transform array elements, creating new data structures or applying calculations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;String manipulation:&lt;/em&gt;&lt;/strong&gt; join() allows you to combine array elements into a single string, useful for formatting data or creating output.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Sorting and filtering:&lt;/strong&gt;&lt;/em&gt; sort() and every() enable you to organize and filter arrays based on specific criteria, ensuring your data is presented in the desired order or meets specific conditions.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>array</category>
      <category>method</category>
      <category>webdev</category>
    </item>
    <item>
      <title>The Importance of Separating Anchor Tags from Buttons in HTML</title>
      <dc:creator>Nurain </dc:creator>
      <pubDate>Thu, 12 Oct 2023 20:36:34 +0000</pubDate>
      <link>https://forem.com/adexbam/the-importance-of-separating-anchor-tags-from-buttons-in-html-27fk</link>
      <guid>https://forem.com/adexbam/the-importance-of-separating-anchor-tags-from-buttons-in-html-27fk</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Mq6QBti1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jcq8yd0jf3awxpsa6bty.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Mq6QBti1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jcq8yd0jf3awxpsa6bty.png" alt="Anchor tag inside Button tag" width="800" height="284"&gt;&lt;/a&gt;&lt;br&gt;
In the world of web development, the rules and best practices for HTML and web design continue to evolve. One common practice that has raised concerns is placing anchor tags &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; inside button elements &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt; . Although it may seem convenient, doing so can lead to unintended consequences and diminish the user experience. In this article, we'll explore the reasons why anchor tags shouldn't be nested within buttons.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Semantic Confusion:
&lt;/h3&gt;

&lt;p&gt;The cornerstone of web development is creating well-structured, semantically meaningful code. Anchor tags &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; are used to create hyperlinks, allowing users to navigate between different pages or resources. On the other hand, buttons &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt; are typically used to trigger actions or functions on the current page. Nesting an anchor tag inside a button can blur the lines between these two distinct HTML elements, creating semantic confusion.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Accessibility Issues:
&lt;/h3&gt;

&lt;p&gt;Web accessibility is a crucial aspect of web design. Screen readers and other assistive technologies rely on the HTML structure to provide accurate information to users with disabilities. When anchor tags are placed inside buttons, it can be challenging for these technologies to interpret the content correctly. Users with disabilities may encounter difficulties when navigating or interacting with the page.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Unpredictable Behavior:
&lt;/h3&gt;

&lt;p&gt;Combining anchor tags and buttons can lead to unpredictable behavior. For instance, when a user clicks on the combined element, it's uncertain whether they will trigger the button's action, follow the link, or both. This unpredictability can result in a frustrating user experience, leaving users unsure of what to expect.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Styling Challenges:
&lt;/h3&gt;

&lt;p&gt;Styling elements is a fundamental aspect of web design. However, combining anchor tags with buttons can create styling challenges. CSS styles may behave unexpectedly when applied to a combined element, making it harder to achieve a consistent and attractive design.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Alternative Solutions:
&lt;/h3&gt;

&lt;p&gt;Instead of nesting anchor tags within buttons, web developers can utilize alternative solutions that maintain a clean and semantically meaningful structure. For example, one can use buttons for actions and anchor tags for navigation. To create a button that resembles a link, CSS can be applied to style the button element. This approach ensures that both actions and navigation are clearly defined and enhances code readability.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In conclusion, the practice of placing anchor tags inside button elements in HTML can lead to a host of issues, including semantic confusion, accessibility problems, unpredictable behavior, styling challenges, and more. By adhering to best practices and keeping the two elements separate, web developers can create a more accessible, predictable, and user-friendly experience for all website visitors.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>html</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
  </channel>
</rss>
