JavaScript - Iterating over JSON object's properties
There are many situations where we have data in JSON format but you have to find the prop name yourself to retrieve the value of it. Here is a simple example to do it.
There are many situations where we have data in JSON format but you have to find the prop name yourself to retrieve the value of it. Here is a simple example to do it.
Many times we uses modules in nodejs applications which comes from different package added in package.json file. This allows us to organize the code and to create reusable components.
Here are simple steps to create your own custom module.
Create a module file mymodule.js
exports.myServerTime = function () {
return "Today is "+Date();
};
In the above code, you would notice a keyword "exports" which make properties and menthods of this module outside of this module file.
In JavaScript, you can use Object Oriented Design concept and one of them is inheritance. In JavaScript, you can create child object from parent object and can override some properties if you want. Here is the example.
We have course Object which has properties name, duration and location with their respective values.
course = {name:'CKD', duration:'3 months', location:'india'}
Now, below we are creating another object with course object but would override duration property.