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
22 responses to “Beginner JavaScript Tutorial – 32 – reverse, push, sort”
If you want to list your array elements as you sort, reverse, push the elements see below. Thanks Bucky for the lessons! Doh, you just covered this in lesson 34.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>JS Lesson 32</title>
<script type="text/javascript">
function listArray(myArray, header) {
// list elements in array
document.write(header + " list:<br />");
for (x = 0; x < myArray.length; x++) {
document.write("myArray[" + x + "]: " + myArray[x] + "<br />");
}
document.write("<hr /><br />");
}
</script>
</head>
<body>
<h2>Lesson 32 – reverese, push, sort</h2>
<hr />
<script type="text/javascript">
var pets = new Array("Daisy", "Moe", "Fluffy", "Truman");
listArray(pets, "Pet");
pets.sort();
listArray(pets, "Pet (sorted)");
pets.reverse();
listArray(pets, "Pet (reversed)");
pets.push("Abbey");
listArray(pets, "Pet (push Abby)");
</script>
</body>
</html>
why doesn't this one work "string1.reverse();" ?
why doesn't this one work "string1.reverse();" ?
why doesn't this one work "string1.reverse();" ?
i am embarrasing because i am slow 10 yaer old typer
120 yeA
119
Thanks
The string is separated even without using "join()" function. Wassup with this? o.o
Why didn't you mention splice? It seems to be very important (through push and pop cover the abilities of splice).
I WON! YAY!
Hi, Bucky, I;m from Israel, thank you for your learn us, about lesson Tutorial No' 32, i have problem ' i could not printing it, something going wrong, even i cheeked it many time, and every thing type right without any mistake,… What could be a problem, and how can i solve it,,. Thank in advance,.
If you wanted to write it faster you could have just written document.write(bp)
so array is a stack in javascript :/
he said titi 😛
Hey Mr bucky!!!
I am a great fan of ur videos these r the best material for any beginner.
thanku so much for ur work,but i have a question
q)- Why do you print the array by using the join command instead we can just write
document.write(array_name);
and this will print the array as a string separated by commas;)
sorry if u consider it as an offense doesnt mean it that way
btw Thanku Soo much.
thank you so much for the tutorial Mr. Bucky.
Great tutorial as always 😀
Head,Shoulders,Tongue,Zoo,apple?,apracotes,hotdog,knees,liver punch
Careful the sort method will put CAPITAL letters first #liverpunch! lol
koji kralj
Why in earth would we use Bp.Push Array when we can just add whatever elements we need in the original array??
32nd haha for a second sound like he said 30 second.