<?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: Brandon Roberts</title>
    <description>The latest articles on DEV Community by Brandon Roberts (@8brandon).</description>
    <link>https://dev.to/8brandon</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%2F163748%2F15912961-29f3-4393-a24f-f0872561e662.png</url>
      <title>DEV Community: Brandon Roberts</title>
      <link>https://dev.to/8brandon</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/8brandon"/>
    <language>en</language>
    <item>
      <title>Global Object Reflect In JavaScript</title>
      <dc:creator>Brandon Roberts</dc:creator>
      <pubDate>Sun, 19 Apr 2020 17:23:55 +0000</pubDate>
      <link>https://dev.to/8brandon/global-object-reflect-in-javascript-813</link>
      <guid>https://dev.to/8brandon/global-object-reflect-in-javascript-813</guid>
      <description>&lt;p&gt;As I was reading Axel's book on Generator functions I came across a new Global Object in Javascript that I never even knew existed!&lt;br&gt;
Reflect&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;22.1.3 Use case: implementing iterables #
The objects returned by generators are iterable; each yield contributes to the sequence of iterated values. Therefore, you can use generators to implement iterables, which can be consumed by various ES6 language mechanisms: for-of loop, spread operator (...), etc.

The following function returns an iterable over the properties of an object, one [key, value] pair per property:

function* objectEntries(obj) {
    const propKeys = Reflect.ownKeys(obj);

    for (const propKey of propKeys) {
        // `yield` returns a value and then pauses
        // the generator. Later, execution continues
        // where it was previously paused.
        yield [propKey, obj[propKey]];
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This was interesting to me that there was this object available so I decided to start to research this more.&lt;/p&gt;

&lt;p&gt;You can learn more about Reflect here.&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect"&gt;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>A better way to turn strings into arrays!</title>
      <dc:creator>Brandon Roberts</dc:creator>
      <pubDate>Wed, 01 Apr 2020 10:39:33 +0000</pubDate>
      <link>https://dev.to/8brandon/a-better-way-to-turn-strings-into-arrays-5fb</link>
      <guid>https://dev.to/8brandon/a-better-way-to-turn-strings-into-arrays-5fb</guid>
      <description>&lt;p&gt;Converting a string to an array is quite a common occurrence for most developers. But I recently found a way to do this that is more concise and readable.&lt;/p&gt;

&lt;h1&gt;
  
  
  How most Javascript developers turn their strings into an array:
&lt;/h1&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const name = "Brandon"
name.split("")
// Result: ["B", "r", "a", "n", "d", "o", "n"]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This works perfectly fine, and is actually the way I see 90%+ of developers covert their strings into an array.&lt;br&gt;&lt;br&gt;
The downside for me is, it's not extremely readable for people who don't know the ins and outs of the Array.split method.&lt;/p&gt;
&lt;h1&gt;
  
  
  The better way to turn your strings into arrays.
&lt;/h1&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const name = "Brandon"
Array.from(name)
// Result: ["B", "r", "a", "n", "d", "o", "n"]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This produces the exact same result as Array.split(""), but here your code reads like a book. Array.from(your_string) is exactly what you want to do.&lt;/p&gt;
&lt;h1&gt;
  
  
  Performance
&lt;/h1&gt;

&lt;p&gt;I did do some research on performance differences between these two ways of converting strings to an array. &lt;br&gt;
I only found one non official blog saying that Array.split is considerably faster than Array.from, however I would be interested to read more tests on this before I'm convinced. If you can provide more info on this topic please leave a comment below. &lt;/p&gt;
&lt;h2&gt;
  
  
  Fun Fact
&lt;/h2&gt;

&lt;p&gt;Another nice thing you can do is turn a Node List into an array, using Array.from.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const pTags = Array.from(document.querySelectorAll('p'));
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With this, you can create a regular array instead of a Node List when using querySelectorAll.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>array</category>
      <category>algorithms</category>
      <category>react</category>
    </item>
  </channel>
</rss>
