JavaScript Looping Through Object Properties
Looping Through JSON Object Properties in JavaScript.
My previous post contained a small piece of code explaining how to loop through object properties with the Reflection namespace in C#.
In this post I'd like to explain how do loop through JavaScript object.
Let's create an object in JavaScript:
This object contains 4 properties:
The function will receive an object and loop through all of it's properties.
I'd like to take 2-4 more lines to explain a bit about the for syntax I used.
Those of you who write in C# / VB / Java will find it very similar to foreach loop in JavaScript.
Since an object in JavaScript is a form of array, I can easily call every one of it's properties the same way (almost) I'd call them when looping through array.
This type of forach loop in JavaScript is also very useful when going through a hash table. since we don't know the numbers the hash contains, we can simply loop through it.
Thanks,
Elad Shalom,
CTO at ITweetLive.com
My previous post contained a small piece of code explaining how to loop through object properties with the Reflection namespace in C#.
In this post I'd like to explain how do loop through JavaScript object.
Let's create an object in JavaScript:
var myObject = {
Name: "Elad",
LastName: "Shalom",
Age: 26,
Kids: ["Daniel"]
};This object contains 4 properties:
- Name (string)
- LastName (string)
- Age (int)
- Kids (array)
function LoopThroughProperties(obj)
{
for (var propName in obj)
{
alert(propName + ": " + obj[propName]);
}
}The function will receive an object and loop through all of it's properties.
I'd like to take 2-4 more lines to explain a bit about the for syntax I used.
Those of you who write in C# / VB / Java will find it very similar to foreach loop in JavaScript.
Since an object in JavaScript is a form of array, I can easily call every one of it's properties the same way (almost) I'd call them when looping through array.
This type of forach loop in JavaScript is also very useful when going through a hash table. since we don't know the numbers the hash contains, we can simply loop through it.
Thanks,
Elad Shalom,
CTO at ITweetLive.com
Ηeya i am for thе primary time here. I found thiѕ board and I
ReplyDeletefind It rеallу helрful & it hеlped
me out muсh. I hopе to give one thing back and aiԁ others suсh as yοu aidеd mе.
my site how much to hire a private investigator uk
michael kors outlet
ReplyDeletelouboutin
fake rolex
levis outlet online
ugg outlet
true religion outlet
ray ban sunglasses outlet
polo ralph lauren
polo outlet
michael kors canada
2061021caiyan
adidas neo
ReplyDeleteyeezy boost 350 v2
adidas superstar
polo lacoste
fitflops
yeezy boost 350 v2
adidas ultra boost
http://www.kobeshoes.uk
salomon speedcross
chrome hearts online
yeezy boost 350 v2
ReplyDeletecoach outlet online
nike roshe flyknit
toms outlet online
coach factory online
ed hardy jeans
ralph lauren outlet
polo ralph lauren
burberry handbags
ralph lauren outlet
2017.3.15chenlixiang
It also means you can move quickly and not have to involve Mortgage Lenders and Valuers in the purchase. Once you have refurbished the property you can then get a surveyor to value the property with a view to placing a mortgage on it and get most if not all of your cash returned.deyaar midtown project
ReplyDeletejordan shoes
ReplyDeleteadidas tubular
jordan shoes
michael kors outlet
nba jerseys
nike air max 97
nike air max 97
russell westbrook shoes
retro jordans
michael kors factory outlet online