96 For in Loop example in JS - JavaScript Tutorial 2018

Pubblicato il: 10 novembre 2017
sul canale di: Ricky Wahowa
31
0

The Full #Javascript #tutorial for #beginners [#JS]:

http://bizanosa.com/js

Learn HTML, CSS and JavaScript

http://bizanosa.com/sp/learn-html-css...

JavaScript Tutorial 2018


96 For in Loop example in Javascript - JavaScript for Beginners.

This is a Javascript tutorial from scratch for any beginner. Use the above link to watch the full JS video tutorial..

Next Video:    • 97 For in Loop example   in JS - JavaScrip...  
Previous Video:    • 95 For in Loop in JS- JavaScript Tutorial ...  


So let’s go in to the browser and then we do an example of a for-in loop in JavaScript.

So if I come back to the browser and then I open Scratchpad, so let’s start by an object.

So we’ll create an object.

Let’s call it ‘var character’ and let’s say we are thinking in terms of a character in a TV show.

So the “name” of the character will be “Joey”.

Then, the TV show, let’s just call it “show” will be “Friends”.

And the “age” of the character is “30”.

So we know that if you’re writing something that is words, you always enclose them in quotation marks.

But if it’s a number like this, you don’t enclose it in quotation marks.

So there we have our object.

Now, we want to iterate using a for-in loop.

And we say that a for-in loop, number 1, for-in, it will bring back the name or the key.

So let’s see what that means.

So if you say ‘for’ and if we look at the syntax, you’ll create a variable to access the object, so a variable to access the object.

So how you do that is you just come back here and let’s say we want to create variable ‘c’, ‘var c’ in character.

So, it will iterate through this character.

And then, if we alert, if we alert ‘c’, we do expect that ‘c’ is going to iterate through everything in this, through all the properties and we say that the property, that’s a property, that’s a property and that’s a property.

And then that, that is a key, that’s a value, that’s a key, that’s a value.

And so, we say that for-in brings back the name.

So if we see the value of ‘c’, it’s going to give us “name”, “show” and “age”, if we iterate through the object using a for-in loop.

So if I run this, Control+Z.

Come down here, alert(c).

If I run this, it will bring back “name” and then the next name is “show”, then next one is “age”.

So it brought back “name”, show and “age”.

Let’s use something that we already know.

Let me just comment out this one.

And before I go any further, before I comment it, let me copy this code because I want to put it in the snippets so that you can take it and use it and change it however you wish.

And now, if you want to bring back the value of this, you can use, let me just comment this one and then we do a different alert down here.

Alert, and you remember how to access, you remember how to access the value in a property.

And you do it using the name ‘character’, using the name of the object.

And then, in this case we’re going to use the square brackets notation.

So, you remember that if you want to access the value in an object, you can use the square brackets notation or you can use the dot notation.

In this case, since this is a variable, we’re going to use the bracket notation.

And what this will bring back to us, it’s going to iterate through all the properties and it’s going to show us the values.

So we can even make it better and say let’s use something that we already know how to use which is the template literals.

So with the template literals, we can say ‘c’ if you want to show the value of ‘c’.

So we’ll just use dollar sign, curly braces and ‘c’.

Then we say ‘c’ is, and then character[c].

Contrl+X.

Let’s put this one also inside, inside of that.

So what this one will tell us is ‘c’ is, so if I run this, it will tell us “name is Joey”, “show is Friends” and the “age is 30”.

So the most important thing you have to understand about the for-in loop is that it will iterate through enumerable properties.

If a property is not enumerable, you can make it non-enumerable, but we’re going to look at that later on when we look at objects in great detail.

So right now know that if you’re using the for-in loop to iterate through objects, it will bring back, the value it will bring back for you will be the name, ok.

It brings back the name, the name, not the values.

So these are the values and these are the names and this entire thing is a property.

So let’s continue on in the next video.



.
GET SOCIAL WITH ME:
FACEBOOK:   / rwahowa  
INSTAGRAM:   / rwahowa  
TWITTER:   / rwahowa  
VIMEO: https://vimeo.com/bizanosa/
WEBSITE : http://rwahowa.com


In questa pagina del sito puoi guardare il video online 96 For in Loop example in JS - JavaScript Tutorial 2018 della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Ricky Wahowa 10 novembre 2017, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 31 volte e gli è piaciuto 0 spettatori. Buona visione!