Lets understand "Objects" in javascript.
Object: It is a collection of property and each property is associated with name value pair. The object can contain any data type.
Lets understand this with the help of an example:
var demoObj = {demoId = "12", demoCode = "007"};
Here,
demoId and demoCode is property name.
12 and 007 are the values associated with the name.
Now, If we want to get the value of 1st property than it can be done using the following syntax:
console.log(demoObj["demoId "]);
Like wise we can get the 2nd value.
There are two types of creating an object:
1. Object literals :
Ex:
var newObj = { };
var newObj = {newId = "11", newCode = "007"};
2. Object constructor
Ex:
var newObj = new object();
newObj.newId = "11";
newObj.newCode = "007";
These are the things that will help you creating objects in Javascript.
0 Comment(s)