day3
unknown
javascript
a year ago
2.0 kB
8
Indexable
// // Objects in javascript
// const person = {
// firstName : 'John',
// lastName : 'Doe',
// age : 30,
// isEmployed : true,
// greet : function(){
// console.log("Hello!");
// }
// };
// //person.firstName
// console.log(person.firstName)
// console.log(person.lastName)
// console.log(person.age)
// console.log(person.isEmployed)
// person.greet()
// Object Constructor
// const person = new Object();
// console.log(person)
// person.firstName = 'John'
// person.lastName = 'Doe'
// person.age = 30;
// person.isEmployed = true;
// person.greet = function(){console.log("Hello!");}
// console.log(person)
// Using Object.create
// const person = Object.create({"University" : 'NIMS'});
// person.firstName = 'John'
// person.lastName = 'Doe'
// person.age = 30;
// person.isEmployed = true;
// person.greet = function(){
// console.log("Hello!");
// }
// console.log(person)
// // Creating on object with a constructor
// functin vehicle(name,maker,engine){
// this.name = name;
// this.maker = maker;
// this.engine = engine;
// }
// // New keyword to run an object
//Iterating over object properties
// const person = {
// firstName : 'John',
// lastName : 'Doe',
// age : 30,
// isEmployed : true,
// greet : function(){
// console.log("Hello!");
// }
// };
// for(let x in person){
// console.log(person.x)
// //console.log(person[x])
// }
// Using has Own Property
// const person = {
// firstName : 'John',
// lastName : 'Doe',
// age : 30,
// isEmployed : true,
// greet : function(){
// console.log("Hello!");
// }
// };
// for(let key in person){
// if(person.hasOwnProperty(key)){
// console.log(key + ' : ' + person[key])
// }
// }
// key = "test"
// if(person.hasOwnProperty(key)){
// console.log(key + ' : ' + person[key])
// }
// else{
// console.log("error")
// }
// Javascript json objects
// all keys are strings in a json objects
Editor is loading...
Leave a Comment