Beginner JavaScript Tutorial – 31 – join and pop




Facebook – https://www.facebook.com/TheNewBoston-464114846956315/
GitHub – https://github.com/buckyroberts
Google+ – https://plus.google.com/+BuckyRoberts
LinkedIn – https://www.linkedin.com/in/buckyroberts
reddit – https://www.reddit.com/r/thenewboston/
Support – https://www.patreon.com/thenewboston
thenewboston – https://thenewboston.com/
Twitter – https://twitter.com/bucky_roberts

Original source


48 responses to “Beginner JavaScript Tutorial – 31 – join and pop”

  1. can any one tell me why the variable name As "name" does not accept in java script.for example if i write a code
    var name= new Array("Ash","Ashish","abhinav","kumar");
    var string = name.join();
    document.write(string);

    this code will not generate desire output but if i will use the variable such as "people" rather than "name" then it will generate output.
    i.e
    var people = new Array("Ash","Ashish","abhinav","kumar");
    var string = people.join();
    document.write(string);

    output:Ash,Ashish,abhinav,kumar

  2. You can also do the opposite to convert a string to array. Example:
    var string1 = "tuna – ham – bacon";
    var groceryList = string1.split(" – ");

    now groceryList is an Array object with "tuna", "ham", "bacon"
    🙂

  3. Just to add to this, the pop() function will return the removed value of the array.
    var arr = new Array("apple", "banana");
    var string1 = arr.pop();

    The variable string1 has the value "banana".

  4. hay can you help me???
    i have a problem in the "for" loop
    he does the loop just one time

    <html>
    <head>
    </head>
    <body>
    <script type="text/javascript">

    var num = new Array (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);

    for (x=0;x<20;X++)
    {
    var string1 = num.join(" – ");
    document.write (string1);
    num.pop();
    document.write (num[19]);
    }

    </script>
    </body>
    </html>

  5. I used this code to see what was happening:
    var movies = new Array ("Wolf of Wall Street", "Sin City", "The Godfather", "Apocalypse Now", "Das Experiment");

    var stop = movies.length;//stop used to control when for loop terminates – in this case it is 5 as there are 5 elements in array

    //This loop prints each element of array and then removes the end element – it loops 5 times
    for (count = 0; count < stop; count++)
    {
    var string1 = movies.join(" – ");//adds all elements of array to string and separates with comma by default or you can put separator in brackets
    document.write(string1 + "<br/>");//prints all the elements of the array
    movies.pop();//removes 1 element of array
    }

  6. in case anyone doesn't know… "Being able to understand technology and control it today, is as fundamental as being able to read and write"… ugh F-YOU treehouse!!! Why advertise on a channel that has hundreds of excellent, free programming videos!?

Leave a Reply