function for object javascript code example
Example 1: js functions inside of objects
var person = {
name: "Fred",
sayName: function() {
console.log(this.name);
}
};
person.sayName();
Example 2: function inside object javascript
var obj = {
func: function(a, b) {
return a * b;
}
};
obj.func(3, 6);
Example 3: how to return an object in javascript
function func() {
return {
name: "Name",
age: 34
};
}
Example 4: 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)
}