<?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: Waqas Rahman</title>
    <description>The latest articles on DEV Community by Waqas Rahman (@vickyktk).</description>
    <link>https://dev.to/vickyktk</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%2F293070%2F3b2d95d3-ddf0-41fe-8e59-a8615d0eb535.jpeg</url>
      <title>DEV Community: Waqas Rahman</title>
      <link>https://dev.to/vickyktk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vickyktk"/>
    <language>en</language>
    <item>
      <title>Get last element of array in JavsScript</title>
      <dc:creator>Waqas Rahman</dc:creator>
      <pubDate>Tue, 18 Jan 2022 17:31:02 +0000</pubDate>
      <link>https://dev.to/vickyktk/get-last-element-of-array-in-javsscript-2n0h</link>
      <guid>https://dev.to/vickyktk/get-last-element-of-array-in-javsscript-2n0h</guid>
      <description>&lt;p&gt;Whatever the programming language you code in ,I am sure you will be playing with arrays every day. So today we will be looking at options we can get the last element of an array in Javascript.&lt;/p&gt;

&lt;p&gt;METHOD 1:INDEXING&lt;/p&gt;

&lt;p&gt;When You know the lenght of the array:&lt;/p&gt;

&lt;p&gt;Say we have the following array&lt;/p&gt;

&lt;p&gt;var myArr = ['Apple', 'Orange', 3, 4, 'Football', 'Cricket'];&lt;br&gt;
So as we know that arrays are zero-indexed in programming, which means that the first element is placed at zero position(Dont tell this to your non-programmer friend). So we just need to count the number of element in the array, which is six(6) in our case so&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(myArr[5])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will print the last element('cricket') for us. Easy Right. Now let's buckle up for the hard part.&lt;/p&gt;

&lt;p&gt;METHOD 2:USING length FUNCTION&lt;/p&gt;

&lt;p&gt;If the array is uncountable for human or coming as function argument than we can use javascript length function to get the last element. This will be like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(myArr[myArr.length - 1])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;myArr.length will give us the array lenght and 1 less from lenght will give the index of last element of the array.&lt;/p&gt;

&lt;p&gt;METHOD 3: USING .pop() FUNCTION&lt;/p&gt;

&lt;p&gt;We can get the last element of array with .pop() function like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let last =myArr.pop()
console.log(last)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But there is a problem with this function as our array will be reduced to five items now as last element is popup out by the function. But if you were to use the array in your code again, you can have a copy 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;let myArray2 = myArr
let last =myArr.pop()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So now myArray2 have all the elements of original array and you can perform any task you want.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>How much of NodeJS is enough ?</title>
      <dc:creator>Waqas Rahman</dc:creator>
      <pubDate>Mon, 25 May 2020 05:32:03 +0000</pubDate>
      <link>https://dev.to/vickyktk/how-much-of-nodejs-is-enough-5d7c</link>
      <guid>https://dev.to/vickyktk/how-much-of-nodejs-is-enough-5d7c</guid>
      <description>&lt;p&gt;Back in January this year I started learning NodeJS.&lt;br&gt;
I have developed many application while working with Modules like &lt;br&gt;
Sockets,EJS,Passport, Express,Mongoose,Express-valditor, Body-Parser ...&lt;/p&gt;

&lt;p&gt;I have worked on Session management, CRUD Operations ,Real Time Chat Application ,Secure Login with PassportJS&lt;/p&gt;

&lt;p&gt;And the main point is now I want to start learning react as at industry level most of them looking for MERN developers So am I ready to go to react or still I need to spend some time with Node.&lt;br&gt;
My GitHUB &lt;a href="https://github.com/vickyktk" rel="noopener noreferrer"&gt;Profile&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks in Advance !!!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Please help</title>
      <dc:creator>Waqas Rahman</dc:creator>
      <pubDate>Wed, 01 Jan 2020 13:47:16 +0000</pubDate>
      <link>https://dev.to/vickyktk/please-help-2jil</link>
      <guid>https://dev.to/vickyktk/please-help-2jil</guid>
      <description>&lt;div class="ltag__stackexchange--container"&gt;
  &lt;div class="ltag__stackexchange--title-container"&gt;
    
      &lt;div class="ltag__stackexchange--title"&gt;
        &lt;div class="ltag__stackexchange--header"&gt;
          &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fstackoverflow-logo-b42691ae545e4810b105ee957979a853a696085e67e43ee14c5699cf3e890fb4.svg" alt=""&gt;
          &lt;a href="https://stackoverflow.com/questions/47751029/i-am-getting-this-error-invalid-parameter-value-for-approval-prompt-auto-is" rel="noopener noreferrer"&gt;
            i am getting this error Invalid parameter value for approval_prompt: 'auto'' is not valid
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="ltag__stackexchange--post-metadata"&gt;
          &lt;span&gt;Dec 11 '17&lt;/span&gt;
            &lt;span&gt;Comments: 1&lt;/span&gt;
            &lt;span&gt;Answers: 1&lt;/span&gt;
        &lt;/div&gt;
      &lt;/div&gt;
      &lt;a class="ltag__stackexchange--score-container" href="https://stackoverflow.com/questions/47751029/i-am-getting-this-error-invalid-parameter-value-for-approval-prompt-auto-is" rel="noopener noreferrer"&gt;
        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fstackexchange-arrow-up-eff2e2849e67d156181d258e38802c0b57fa011f74164a7f97675ca3b6ab756b.svg" alt=""&gt;
        &lt;div class="ltag__stackexchange--score-number"&gt;
          6
        &lt;/div&gt;
        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fstackexchange-arrow-down-4349fac0dd932d284fab7e4dd9846f19a3710558efde0d2dfd05897f3eeb9aba.svg" alt=""&gt;
      &lt;/a&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--body"&gt;
    
&lt;p&gt;this is the error i am getting&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;400. That’s an error.

Error: invalid_request

Invalid parameter value for approval_prompt: 'auto'' is not valid
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Request Details&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;response_type=code
access_type=offline
client_id=xyz-
xyx.apps.googleusercontent.com
redirect_uri=http://localhost/xyz/init/googleCallBack.php
state=scope=https://www.googleapis.com/auth/plus.me
approval_prompt=auto'
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;here is the config for google login&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$gClient= new Google_Client();
$gClient-&amp;gt;setAuthConfig('init/client_secret.json');

$gClient-&amp;gt;setApprovalPrompt('consent');
$gClient-&amp;gt;setApplicationName('abc');
$gClient-&amp;gt;setAccessType('offline');
$gClient&amp;gt;setRedirectUri('http://localhost/xyz/init/googleCallBack.php';
$gClient-&amp;gt;setScopes(Google_Service_Plus::PLUS_ME);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;i tried setting…&lt;/p&gt;
    
  &lt;/div&gt;
  &lt;div class="ltag__stackexchange--btn--container"&gt;
    &lt;a href="https://stackoverflow.com/questions/47751029/i-am-getting-this-error-invalid-parameter-value-for-approval-prompt-auto-is" class="ltag__stackexchange--btn" rel="noopener noreferrer"&gt;Open Full Question&lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;


</description>
    </item>
  </channel>
</rss>
