Monday, May 2, 2022
Instead of testing to see if a property exists in the object you could just use the for/in loop to iterate through all the enumerable properties in the object. Enumerable properties are the properties that owned by the object. In JavaScript there are always two objects that are created with each object, one hidden object that's always there is the prototype object. It's like the blueprint for the object you just created. The owned properties are the properties that explicitly created with your object. The prototype properties are what's called inherited properties. So if we use the for/in loop we will get the owned properties and the prototype properties.
So to use the for/in loop to iterate through the object let's use our product object again.
Now type in the following to loop through the object with the for/in loop and outputs the property name and property value to the console
As you can see we only got through the first level of the properties, since supplier is nested object how do we get the properties for it? You would think it's as easy as changing the code to have nested for/in loop would do the trick.
Like this
But as you can see that's not the case, instead you get the characters of the property names. As you can see the supplier property is actually an object itself.
So to use the for/in loop to iterate through the object let's use our product object again.
var product = new Object();product.name = "Chai";product.category = "Tea";product.country = "India";product.supplier = {name: "ACME Tea Of India",location: "New Delhi"};
Now type in the following to loop through the object with the for/in loop and outputs the property name and property value to the console
for (prop in product)console.log(prop + ": " + product[prop]);
As you can see we only got through the first level of the properties, since supplier is nested object how do we get the properties for it? You would think it's as easy as changing the code to have nested for/in loop would do the trick.
Like this
for(prop in product)
{
console.log(prop + ": " + product[prop]);
for(p in prop)
console.log(p + ": " + prop[p]);
}
But as you can see that's not the case, instead you get the characters of the property names. As you can see the supplier property is actually an object itself.
Subscribe to:
Post Comments (Atom)
Search This Blog
Tags
Web Development
Linux
Javascript
DATA
CentOS
ASPNET
SQL Server
Cloud Computing
ASP.NET Core
ASP.NET MVC
SQL
Virtualization
AWS
Database
ADO.NET
AngularJS
C#
CSS
EC2
Iaas
System Administrator
Azure
Computer Programming
JQuery
Coding
ASP.NET MVC 5
Entity Framework Core
Web Design
Infrastructure
Networking
Visual Studio
Errors
T-SQL
Ubuntu
Stored Procedures
ACME Bank
Bootstrap
Computer Networking
Entity Framework
Load Balancer
MongoDB
NoSQL
Node.js
Oracle
VirtualBox
Container
Docker
Fedora
Java
Source Control
git
ExpressJS
MySQL
NuGet
Blogger
Blogging
Bower.js
Data Science
JSON
JavaEE
Web Api
DBMS
HTML5
MVC
SPA
Storage
github
AJAX
Big Data
Design Pattern
DevOps
Eclipse IDE
Elastic IP
GIMP
Graphics Design
Heroku
Postman
R
SSL
Security
Visual Studio Code
ASP.NET MVC 4
CLI
Linux Commands
Powershell
Python
Server
Subnets
Telerik
VPC
Windows Server 2016
angular-seed
font-awesome
log4net
servlets
tomcat
AWS CloudWatch
Active Directory
Angular
Blockchain
Collections
Compatibility
Cryptocurrency
DIgital Life
DNS
Downloads
Google Blogger
Google Chrome
Google Fonts
Hadoop
IAM
KnockoutJS
LINQ
Linux Performance
Logging
Mobile-First
Open Source
Prototype
R Programming
Responsive
Route 53
S3
SELinux
Software
Software Development
Unix
View
Web Forms
WildFly
XML
cshtml
githu
Finding help with accounting assignments is easier than you think; all you need is to search online for an accounting assignment expert. But stay vigilant while ordering such services from the websites offering accounting assignment help and only pay if you are confident with the final draft you would be getting because we don’t want you to get deceived afterward. Accounting is not only a subject; instead, it is the discipline of every organization. It helps to analyze the financial transactions of every sector. It is a subject that can gift you the best jobs abroad. So, when you need to write your accounting assignment, do not write it haphazardly. There are accounting assignment experts available to solve your problem and offer you the best quality content.
ReplyDeleteThank you so much for sharing this thread with us, It's a good post..keep posting and updating the more information like this. By the way, I am a professional javascript academic writer and provide Assignment help services to the students in Australia.
ReplyDeleteAlways examine the player desk every day to find out about every day 1Xbet promotions and special offers; lots of them usually are not advertised on-line. In reality, it might have the opposite effect and result in bigger losses. When you cease a slot machine by your self, you scale back the 'time of spin' , making the sport go quicker.
ReplyDelete
ReplyDeleteThis is a nice article for sharing great information. Thank you for providing such a wonderful and educative update. I would appreciate it if you could keep sharing.- what is skyline university cut off mark