Objects

Basic

// objects in const/let/var always starts with {name:value, name:value, etc}
const myObject = { 
    title : 'lord of the rings',
    author : 'Faizal',
    publish : '9/5/1988'
    }
    
console.log(myObject) 
// { title : 'lord of the rings,author : 'Faizal',publish : '9/5/1988'}

Edit object

const myObject = { 
    title : 'lord of the rings',
    author : 'Faizal',
    publish : '9/5/1988'
    }
    
console.log(myObject,'my object before')

myObject.title = 'entrepreneurs 4.0'
 
console.log(myObject,'my object after')

// { title : 'entrepreneurs 4.0' ,author : 'Faizal',publish : '9/5/1988'}

Add object

const myObject = { 
    title : 'lord of the rings',
    author : 'Faizal',
    publish : '9/5/1988'
    }
    
console.log(myObject,'my object before) 

myObject.type = 'non-fiction'

console.log(myObject,'my object after) 

// { title : 'lord of the rings,author : 'Faizal',publish : '9/5/1988', type : 'non-fiction'}

Change & add object

const myObject = { 
    title : 'lord of the rings',
    author : 'Faizal',
    publish : '9/5/1988'
    }

console.log(myObject ,'my object before') 

myObject.title = 'outliers';
myObject.author = 'malcolm gladwell';
myObject.publish = '10/12/2020';
myObject.type = 'non-fiction';

console.log(myObject ,'my object after') 
//{title:'outliers', author:'malcolm gladwell', publish:'10/12/2020', type:'non-fiction'}

Last updated

Was this helpful?