javascript object functions code example
Example 1: how to define function in object javascript
let example = {
calc: function (num1, num2) {
return num1 + num2;
},
};
example.calc(1,2)
Example 2: object object javascript
person = {
'name':'john smith'
'age':41
};
console.log(person);
console.log(JSON.stringify(person));
Example 3: object methods in javascript
const testScore = {
damon: 89,
shawn: 91,
keenan: 80,
kim: 89,
};
Object.keys(testScore);
Object.values(testScore);
Object.entries(testScore);
for (let person in testScore) {...}
for(let score of Object.values(testScore)){
console.log(score)
}
Example 4: objects in javascript
let name = {
name1: 'mark'
}