<?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>DEV Community: Tobi Ajibade</title>
    <description>The latest articles on DEV Community by Tobi Ajibade (@oxwware).</description>
    <link>https://dev.to/oxwware</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%2F134096%2Fa5b68b39-4cc4-4f57-955a-5ebdbb6ebeb9.jpg</url>
      <title>DEV Community: Tobi Ajibade</title>
      <link>https://dev.to/oxwware</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/oxwware"/>
    <language>en</language>
    <item>
      <title>How to convert a Js string to an array</title>
      <dc:creator>Tobi Ajibade</dc:creator>
      <pubDate>Mon, 09 Mar 2020 11:13:35 +0000</pubDate>
      <link>https://dev.to/oxwware/how-to-convert-a-js-string-to-an-array-3g29</link>
      <guid>https://dev.to/oxwware/how-to-convert-a-js-string-to-an-array-3g29</guid>
      <description>&lt;p&gt;How to convert a Js string to an array&lt;br&gt;
        &lt;/p&gt;
&lt;p&gt;A string can be converted into an array with the &lt;code&gt;String.split()&lt;/code&gt; method. The &lt;code&gt;String.split()&lt;/code&gt; method turns or changes a string into an array of strings, by seperating the string at each instance of a special seperator string. What do it mean? let consider an example to explain the phrase.&lt;/p&gt;

&lt;h3&gt;Example 1 :&lt;/h3&gt;

&lt;p&gt;The example below show a string been seperated by comma(,) :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     &amp;lt;pre&amp;gt;
         var str = "My,name,is,Tobi,Ajibade";
     &amp;lt;/pre&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now to convert this string into an array, we will use the &lt;br&gt;
 &lt;code&gt;string.split(",")&lt;/code&gt; method with a comma seperator assigned to it. To do that let me list the various ways a string can be converted to an array.&lt;/p&gt;
&lt;br&gt;
         &lt;ol&gt;

             &lt;li&gt;string.split(",") // It will seperate the string on comma(,) &lt;/li&gt;

             &lt;li&gt;string.split(" ") // It will seperate the string on a single space( ), string.split("  ") It will seperate the string on a double space and so on&lt;/li&gt;

             &lt;li&gt;string.split() // It will return all the string as a single array&lt;/li&gt;

             &lt;li&gt;string.split("") // It will seperate the string on a single character &lt;/li&gt;

         &lt;/ol&gt;
&lt;br&gt;
         &lt;p&gt;Now, let solve example 1 :&lt;/p&gt;
&lt;br&gt;
         &lt;pre&gt;var str = "My,name,is,Tobi,Ajibade";&lt;br&gt;
 str.split(","); // Would return an array with value : ["My","name","is","Tobi","Ajibade"];&lt;br&gt;
             //You should try it in your browser console;&lt;br&gt;
         &lt;/pre&gt;
&lt;br&gt;
 &lt;p&gt;Now we know how to seperate a string with a comma seperator&lt;/p&gt;
&lt;br&gt;
 &lt;h3&gt;Using the &lt;code&gt;String.split()&lt;/code&gt;
&lt;/h3&gt;
&lt;br&gt;
         &lt;pre&gt;&lt;br&gt;
             var str = "Am a coder";&lt;br&gt;
             str.split(); // Would return an array with value : ["Am a coder"];&lt;br&gt;
             // it would return all the string because it has no specified seperator&lt;br&gt;
             //You should try it in your browser console&lt;br&gt;
         &lt;/pre&gt;
&lt;br&gt;
 &lt;h3&gt;Using the &lt;code&gt;String.split()&lt;/code&gt; with space seperator&lt;/h3&gt;
&lt;br&gt;
         &lt;pre&gt;&lt;br&gt;
             var str = "Am a front-end developer";&lt;br&gt;
             str.split(" "); // Would return an array with value : ["Am","a","front-end","developer"];&lt;br&gt;
             //You should try it in your browser console&lt;br&gt;
         &lt;/pre&gt;
&lt;br&gt;
 &lt;h3&gt;Using the &lt;code&gt;String.split()&lt;/code&gt; to seperate a single character&lt;/h3&gt;
&lt;br&gt;
         &lt;pre&gt;&lt;br&gt;
 var str = "I can code";&lt;br&gt;
 str.split(""); // Would return an array with value : ["I","C","a","n","c","o","d","e"];&lt;br&gt;
             //You should try it in your browser console&lt;br&gt;
   &lt;/pre&gt;

&lt;p&gt;But what Would happen if you have a special character like an emoji or smiley : 🧓👩‍🦰🎅😁😍❤💔 , let see&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     &amp;lt;pre&amp;gt;
        var str = "I 🤣 to code";
        str.split(""); // Would return an array with value : ["I", " ", "�","�", " ", "t", "o", " ", "c", "o", "d", "e"]
        //You should try it in your browser console
     &amp;lt;/pre&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You would notice it didn't output the smiley, it output a "�". These happens because "when an empty string ("") is used as a seperator, The string is not split by user-perceived characters, but by UTF-16 codeunits and this destroys the surogate parts(like emoji and icons)."  So how do we solve this? Using Array.from() or spread operator [...str].&lt;/p&gt;
&lt;br&gt;
 &lt;h3&gt;Using &lt;code&gt;Array.from()&lt;/code&gt;
&lt;/h3&gt;
&lt;br&gt;
  &lt;p&gt;The Array.from() method creates a new, shallow-copied Array instance from an array-like or iterable object. &lt;br&gt;
             &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from"&gt;Read more on array.from() on MDN&lt;/a&gt;&lt;br&gt;
         &lt;/p&gt;
&lt;br&gt;
         &lt;pre&gt;&lt;br&gt;
             var str = "Tobi 😁 love to code";&lt;br&gt;
             Array.from(str); // would output : ["T", "o", "b", "i", " ", "😁", " ", "l", "o", "v", "e", " ", "t", "o", " ", "c", "o", "d", "e"]&lt;br&gt;
         &lt;/pre&gt;
&lt;br&gt;
 &lt;h3&gt;Using the spread operator&lt;/h3&gt;
&lt;br&gt;
 &lt;p&gt;Spread syntax allows an iterable such as an array expression or string to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected, or an object expression to be expanded in places where zero or more key-value pairs (for object literals) are expected. &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax"&gt;Read more on spread operator on MDN&lt;/a&gt;&lt;/p&gt;
&lt;br&gt;
             &lt;pre&gt;&lt;br&gt;
                 var str = "Hello tobi 🧡👀💋🎶 to code";&lt;br&gt;
                 [...str]; // would output : ["H", "e", "l", "l", "o", " ", "t", "o", "b", "i", " ", "🧡", "👀", "💋","🎶", " ", "t", "o", " ", "c", "o", "d", "e"]&lt;br&gt;
             &lt;/pre&gt;

&lt;p&gt;Note : You are not limited to only this 4 split() seperator, you can split a string into an array by any seperator be it ("," "" | \ e.t.c);
                 &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split"&gt;Read more on &lt;code&gt;string.split() on MDN&lt;/code&gt;&lt;/a&gt;
             &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;         &amp;lt;p&amp;gt;Thanks for reading! You can ask me questions in the comment section. I would be writing an another article soon on Javascript Node&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>javascript</category>
      <category>string</category>
      <category>array</category>
      <category>stringmethod</category>
    </item>
    <item>
      <title>Javascript Ternary Operator</title>
      <dc:creator>Tobi Ajibade</dc:creator>
      <pubDate>Fri, 24 Jan 2020 19:13:35 +0000</pubDate>
      <link>https://dev.to/oxwware/javascript-ternary-operator-af</link>
      <guid>https://dev.to/oxwware/javascript-ternary-operator-af</guid>
      <description>&lt;h1&gt;Conditional or ternary Operator&lt;/h1&gt;

&lt;p&gt;A conditional operator assigns a specified value to a variable based on some conditions, i.e it assigns a value to a variable if a condition is true , otherwise assigns an alternate value if condition is false.&lt;/p&gt;

&lt;p&gt;Syntax&lt;/p&gt;

&lt;p&gt;&lt;code&gt;variable name = (condition) ? value1 : value2;&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;Practical Example&lt;/h3&gt;

&lt;p&gt;Let write a script to check how experience a web developer is, depending on their years of experience in the industry&lt;/p&gt;

&lt;p&gt;Javascript code&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
function checkExp() {
var input, output;
input = document.getElementById("expcheck").value;
  output = (input &amp;lt; 2) ? "You're a young developer" : "You're an experienced developer";
document.getElementById("output").innerHTML = output;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt; Below is the snippet in codepen&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/tohbi/embed/KKwEaNV?height=600&amp;amp;default-tab=js,result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;This is actually my first post. Thanks for reading!&lt;/p&gt;

&lt;p&gt;Free to hit me up in the comment section.&lt;/p&gt;


&lt;div class="ltag__user ltag__user__id__"&gt;
    &lt;div class="ltag__user__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xtH13c6f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--diPD5F8K--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://thepracticaldev.s3.amazonaws.com/i/99mvlsfu5tfj9m7ku25d.png" alt="[deleted user] image"&gt;
    &lt;/div&gt;
  &lt;div class="ltag__user__content"&gt;
    &lt;h2&gt;[Deleted User]&lt;/h2&gt;
    &lt;div class="ltag__user__summary"&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>codifynigeria</category>
    </item>
    <item>
      <title>FCC:Tribute Page</title>
      <dc:creator>Tobi Ajibade</dc:creator>
      <pubDate>Tue, 17 Dec 2019 06:13:44 +0000</pubDate>
      <link>https://dev.to/oxwware/fcc-tribute-page-3c7j</link>
      <guid>https://dev.to/oxwware/fcc-tribute-page-3c7j</guid>
      <description>&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/tohbi/embed/OJPRqqR?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;br&gt;
?signin=true&lt;/p&gt;

</description>
      <category>codepen</category>
    </item>
  </channel>
</rss>
