Monday, October 25, 2021
Now that we've learned to create objects in all sorts of ways it's time to set and get the object properties that we've created. In this blog we will go over how to access the object properties either to set them or get them.
First let's create an object that we can work with:
Type in the following code in the between the <script type="text/javascript"></script> tag in an html page.
Now that we have our object let's start changing the properties. There are two ways you can get and set properties. You can either set the properties using the .dot notations or you can use the [] operators to access the properties. First let's get the properties with these two methods. Add the following lines to the code above.
As you can see they both got the job done if you look at the console in your browser. With both methods we were able to retrieve the values for the product name, and category.
Now let's do the same to set the properties for our product. First let's set the name property to "Dark Roast" using the dot notation. product.name = "Dark Roast"; Now let's set the category to be "Coffee" with the bracket operators. product["category"] = "Coffee"; If we look at the browser console again we will see that the name, and category has been changed.
Here is the complete code for this example:
First let's create an object that we can work with:
Type in the following code in the between the <script type="text/javascript"></script> tag in an html page.
var product = new Object(); product.name = "Chai"; product.category = "Tea"; product.country = "India"; product.supplier = { name: "ACME Tea Of India", location: "New Delhi" }; console.log(product);If you run the page with the code above you will see the following in the browser console:
Now that we have our object let's start changing the properties. There are two ways you can get and set properties. You can either set the properties using the .dot notations or you can use the [] operators to access the properties. First let's get the properties with these two methods. Add the following lines to the code above.
console.log(product.name); console.log(product["category"]);
As you can see they both got the job done if you look at the console in your browser. With both methods we were able to retrieve the values for the product name, and category.
Now let's do the same to set the properties for our product. First let's set the name property to "Dark Roast" using the dot notation. product.name = "Dark Roast"; Now let's set the category to be "Coffee" with the bracket operators. product["category"] = "Coffee"; If we look at the browser console again we will see that the name, and category has been changed.
Here is the complete code for this example:
<!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8" /> <script type="text/javascript"> var product = new Object(); product.name = "Chai"; product.category = "Tea"; product.country = "India"; product.supplier = { name: "ACME Tea Of India", location: "New Delhi" }; product.name = "Dark Roast"; product["category"] = "Coffee"; console.log(product); console.log(product.name); console.log(product["category"]); </script> </head> <body> </body> </html>
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
DevOps
HTML5
MVC
SPA
Storage
github
AJAX
Big Data
Design Pattern
Eclipse IDE
Elastic IP
GIMP
Graphics Design
Heroku
Linux Mint
Postman
R
SSL
Security
Visual Studio Code
ASP.NET MVC 4
CLI
Linux Commands
Powershell
Python
Server
Software Development
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
Unix
View
Web Forms
WildFly
XML
cshtml
githu
Looking for LCD TV repair Dubai, LED TV repair Dubai? MIRZA IJAZ ELECTRICAL DEVICES repairing Dubai is here to solve you.
ReplyDeleteReally I like your article it is easy to reading. You are a good blogger pls keep it up. Thank you so much. We offer incomparable Dissertation Writing Services uk
ReplyDeleteThese JavaScript Objects Deep Dive : Setting And Getting Properties, which are so authentic and reflective to having from them but there are also very beneficial and authorized private blog network links available to getting from them in all over the USA so easily.
ReplyDeleteWith the help of Data mining assignment help you can easily get your assignment done by the experts and that too having thorough support for any assistance, if needed. So, never compromise with your assignment rather than asking for Data mining assignment help.
ReplyDeleteThis blog post provides valuable insights into setting and getting object properties, empowering developers to effectively utilize this fundamental aspect of object-oriented programming. And when it comes to reliable Earthwork service texas in USAunderstanding object properties can aid in optimizing project management and enhancing operational efficiency.
ReplyDeleteYou have flexible options to get and set properties in your code. Atleadingit company in UAE, we understand the significance of efficient property manipulation and can assist you in optimizing your code to ensure smooth execution and enhanced performance. Let us help you leverage the power of object properties in your programming endeavors.
ReplyDeleteProgramming success depends on knowing how to set and retrieve object properties. Accessing and modifying object properties enables developers to customise and optimise their code, opening up limitless possibilities and assuring effective data vinyl fencing edmonton in canadamanagement, just like Edmonton homeowners depend on high-quality residential vinyl fencing to beautify their properties.
ReplyDeleteUnderstanding how to access and manipulate object properties is a fundamental skill in programming. This blog provides valuable insights on setting and retrieving object properties, helping developers enhance their coding skills. And for a comprehensive car cleaning experience, consider Ottawa Car Wash for professional and reliable car washing services.
ReplyDeleteMastering the art of accessing and manipulating object properties is essential in web development. When it comes to optimizing your online presence, seo services dubaican help enhance visibility, improve search rankings, and drive organic traffic to your website, ensuring your digital success.
ReplyDeleteThe convenience of independently setting and adjusting cooking temperatures for different dishes, resulting in precise cooking and optimal flavor. With its versatile functionality, Best double oven electric rangeempowers you to unleash your culinary creativity and achieve exceptional cooking results.
ReplyDeleteJust like setting and getting object properties, chemical injection in UAEensures precise control and efficient distribution of chemicals for various industrial applications. Both processes enhance functionality and optimize performance.
ReplyDelete"JavaScript Objects Deep Dive: Setting and Getting Properties" is a comprehensive guide that delves into the intricacies of working with objects in JavaScript. As you explore this topic, consider how efficient property setting and getting techniques can be as essential to programming as precise methods employed in INFILL DEMOLITION in Albertaensuring optimal results and seamless functionality.
ReplyDeleteJavaScript Objects Deep Dive" - Dive into the world of JavaScript objects and explore their complexities. When it's time to refuel during heavy equipment operations, rely on Heavy equipment catering in houston texas for nourishing meals and refreshments. Happy learning!
ReplyDeleteJavaScript Objects Deep Dive: Setting And Getting Properties" delves into programming intricacies. Just as this exploration dissects code elements,Best Barber Shop in Canada offer a detailed approach to grooming, addressing specific needs and preferences for a tailored experience that goes beyond the surface
ReplyDeleteJavaScript Objects Deep Dive: Setting And Getting Properties is an insightful exploration of programming. Likewise, explore the world of auto detailing with Ottawa Car Detailing services where attention to detail results in a vehicle that looks as good as new. Just as this deep dive enhances coding skills, quality detailing enhances your car's aesthetics and condition.
ReplyDeleteExploring JavaScript objects is like fine-tuning your programming toolkit. Just as you seek quality components, when it comes to kdk air curtain suppliers in uae look for reliable suppliers like KDK. Both in coding and cooling, precision matters! 🖥️❄️ #JavaScript #KDKAirCurtains #ProgrammingTips
ReplyDeleteJavaScript Objects Deep Dive: Setting and Getting Properties is an essential resource for mastering this foundational programming concept. Just as precision is key in coding, finding thecoffee beans dubai is crucial for coffee enthusiasts. Explore the world of coffee beans in Dubai to elevate your coffee experience to the next level. ☕🖥️🌍
ReplyDeleteJavaScript Objects Deep Dive: Setting and Getting Properties" is an essential resource for developers looking to master this fundamental concept. Just as you dive deep into JavaScript objects, tank cleaning houstonshould ensure they maintain their tanks with effective tank cleaning solutions.
ReplyDeleteJavaScript Objects Deep Dive" is an invaluable resource for web developers, and much like the precision needed in brewing coffee beans dubaia perfect cup of coffee, this tutorial dives deep into the intricacies of setting and getting properties in JavaScript objects. Just as the right beans are essential for a flavorful brew.
ReplyDelete
ReplyDeleteMastering object creation and property manipulation opens doors to endless possibilities in programming. Similarly, for crafting versatile and functional spaces, consult a leading fit out company in UAE.
Mastering object creation and property manipulation opens endless possibilities in programming! Just like refining code, trust fit out contractors Dubai to meticulously craft spaces tailored to your exact specifications and needs.
ReplyDeleteUnlocking the power of object properties is essential for effective programming. While you delve into this topic, ensure your surroundings are safe and sound with emergency demolition contractors in Edmonton for peace of mind.
ReplyDeleteCheap ghostwriting services offer a budget-friendly way to get professional content for your projects, ensuring you don't compromise on quality while saving money.
ReplyDelete