<?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>ES6 &#8211; Learn Beginner</title>
	<atom:link href="https://learnbeginner.com/tag/es6/feed/" rel="self" type="application/rss+xml" />
	<link>https://learnbeginner.com</link>
	<description>Start Your Tech Journey With Us &#124; Smart Learning, Great Beginning</description>
	<lastBuildDate>Tue, 06 Oct 2020 13:26:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.2</generator>

<image>
	<url>https://learnbeginner.com/wp-content/uploads/2021/02/favicon.png</url>
	<title>ES6 &#8211; Learn Beginner</title>
	<link>https://learnbeginner.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>The fastest way to convert array like object into js array</title>
		<link>https://learnbeginner.com/the-fastest-way-to-convert-array-like-object-into-js-array/</link>
					<comments>https://learnbeginner.com/the-fastest-way-to-convert-array-like-object-into-js-array/#respond</comments>
		
		<dc:creator><![CDATA[Hiren Vaghasiya]]></dc:creator>
		<pubDate>Wed, 06 May 2020 18:38:53 +0000</pubDate>
				<category><![CDATA[Beginners Guide]]></category>
		<category><![CDATA[Dev Tips]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[ES6]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Web Development]]></category>
		<guid isPermaLink="false">https://learnbeginner.com/?p=2615</guid>

					<description><![CDATA[In this fast programming era every developer face this issue including me. So I am finding best and fastest way to convert array like object into js array.]]></description>
										<content:encoded><![CDATA[
<p>In this fast programming era every developer face this issue including me. So I am finding best and fastest way to convert array like object into js array.</p>



<h4 class="wp-block-heading">1. What is the problem?</h4>



<p>Suppose you have a list of divs on your page and you query them via&nbsp;<code>document.querySelectorAll</code>.</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">let rows = document.querySelectorAll('img')
NodeList(11) </code></pre>



<p>However,&nbsp;<code>rows</code>&nbsp;is not an array that you can manipulate with all of the handy array methods, like&nbsp;<code>map(), filter()</code>etc.</p>



<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1185" height="428" src="https://i2.wp.com/learnbeginner.com/wp-content/uploads/2020/05/0015-1_4MkBJprFSx6GXT4os8b-4g.png?fit=770%2C278" alt="" class="wp-image-2617" srcset="https://learnbeginner.com/wp-content/uploads/2020/05/0015-1_4MkBJprFSx6GXT4os8b-4g.png 1185w, https://learnbeginner.com/wp-content/uploads/2020/05/0015-1_4MkBJprFSx6GXT4os8b-4g-300x108.png 300w, https://learnbeginner.com/wp-content/uploads/2020/05/0015-1_4MkBJprFSx6GXT4os8b-4g-1024x370.png 1024w, https://learnbeginner.com/wp-content/uploads/2020/05/0015-1_4MkBJprFSx6GXT4os8b-4g-150x54.png 150w, https://learnbeginner.com/wp-content/uploads/2020/05/0015-1_4MkBJprFSx6GXT4os8b-4g-768x277.png 768w, https://learnbeginner.com/wp-content/uploads/2020/05/0015-1_4MkBJprFSx6GXT4os8b-4g-370x134.png 370w, https://learnbeginner.com/wp-content/uploads/2020/05/0015-1_4MkBJprFSx6GXT4os8b-4g-270x98.png 270w, https://learnbeginner.com/wp-content/uploads/2020/05/0015-1_4MkBJprFSx6GXT4os8b-4g-570x206.png 570w, https://learnbeginner.com/wp-content/uploads/2020/05/0015-1_4MkBJprFSx6GXT4os8b-4g-740x267.png 740w" sizes="(max-width: 1185px) 100vw, 1185px" /><figcaption>oops, I am not an array, buddy</figcaption></figure>



<p>That is because</p>



<pre class="wp-block-verse"><code>NodeList</code>&nbsp;object is a list (collection) of nodes extracted from a document.</pre>



<p>So after this the question is &#8220;What can We do?&#8221;</p>



<h4 class="wp-block-heading"><strong>2. What can I do?</strong></h4>



<p>The easiest, fastest way to convert it into an array is just using the es6 spread operator.</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">let rows = document.querySelectorAll('img');
rows = [...rows]</code></pre>



<p>Now, you can start applying all of the array methods to this&nbsp;<code>rows</code></p>



<figure class="wp-block-image size-large"><img decoding="async" width="1400" height="221" src="https://i2.wp.com/learnbeginner.com/wp-content/uploads/2020/05/0016-1_dxLqg6bhRVEyDl9nHzKJwA.png?fit=770%2C122" alt="" class="wp-image-2618" srcset="https://learnbeginner.com/wp-content/uploads/2020/05/0016-1_dxLqg6bhRVEyDl9nHzKJwA.png 1400w, https://learnbeginner.com/wp-content/uploads/2020/05/0016-1_dxLqg6bhRVEyDl9nHzKJwA-300x47.png 300w, https://learnbeginner.com/wp-content/uploads/2020/05/0016-1_dxLqg6bhRVEyDl9nHzKJwA-1024x162.png 1024w, https://learnbeginner.com/wp-content/uploads/2020/05/0016-1_dxLqg6bhRVEyDl9nHzKJwA-150x24.png 150w, https://learnbeginner.com/wp-content/uploads/2020/05/0016-1_dxLqg6bhRVEyDl9nHzKJwA-768x121.png 768w, https://learnbeginner.com/wp-content/uploads/2020/05/0016-1_dxLqg6bhRVEyDl9nHzKJwA-370x58.png 370w, https://learnbeginner.com/wp-content/uploads/2020/05/0016-1_dxLqg6bhRVEyDl9nHzKJwA-270x43.png 270w, https://learnbeginner.com/wp-content/uploads/2020/05/0016-1_dxLqg6bhRVEyDl9nHzKJwA-570x90.png 570w, https://learnbeginner.com/wp-content/uploads/2020/05/0016-1_dxLqg6bhRVEyDl9nHzKJwA-740x117.png 740w" sizes="(max-width: 1400px) 100vw, 1400px" /><figcaption>get me those images that I want!</figcaption></figure>



<h4 class="wp-block-heading">3. Other ways to solve the problem here</h4>



<ol class="wp-block-list"><li>use es6 spread operator<strong>&nbsp;[…arrayLikeObject]</strong></li><li>usees6<strong>&nbsp;Array.from</strong>(arrayLikeObject)</li><li><strong>[].slice.call</strong>(arrayLikeObject)</li><li>use the good old&nbsp;<strong>for</strong>&nbsp;loop, code snippet is below, feel free to copy it, LOL</li></ol>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">let trueArray = []
for(let i = 0; i &lt; rows.length; i++) {
   trueArray.push(rows[i])
}</code></pre>



<p>If you know any other ways, feel free to leave a comment below!</p>



<div class="wp-block-jetpack-markdown"><p>Thanks for reading! ? If you find this helpful don’t forget to give some claps ?? and feel free to share this with your friends and followers! ?If you have some tips to share, feel free to comment below.</p>
</div>


<script>(function() {
	window.mc4wp = window.mc4wp || {
		listeners: [],
		forms: {
			on: function(evt, cb) {
				window.mc4wp.listeners.push(
					{
						event   : evt,
						callback: cb
					}
				);
			}
		}
	}
})();
</script><!-- Mailchimp for WordPress v4.10.2 - https://wordpress.org/plugins/mailchimp-for-wp/ --><form id="mc4wp-form-1" class="mc4wp-form mc4wp-form-2830 mc4wp-form-theme mc4wp-form-theme-dark" method="post" data-id="2830" data-name="Main Newsletter" ><div class="mc4wp-form-fields"><p>
	<label> 
		<input type="email" name="EMAIL" placeholder="Your email address"  style="max-width: 100%;" required />
	</label>
	<input type="submit" value="Subscribe Now" style="width: 100%;" />
</p></div><label style="display: none !important;">Leave this field empty if you&#8217;re human: <input type="text" name="_mc4wp_honeypot" value="" tabindex="-1" autocomplete="off" /></label><input type="hidden" name="_mc4wp_timestamp" value="1742409858" /><input type="hidden" name="_mc4wp_form_id" value="2830" /><input type="hidden" name="_mc4wp_form_element_id" value="mc4wp-form-1" /><div class="mc4wp-response"></div></form><!-- / Mailchimp for WordPress Plugin -->]]></content:encoded>
					
					<wfw:commentRss>https://learnbeginner.com/the-fastest-way-to-convert-array-like-object-into-js-array/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
