I'm a newbie to Javascript. I wish to know how to get the key as 'personObj', 'carObj, 'workDetailsObj', 'displayFunction' and 'primitiveValue' and print those values in console? Also, how to print the value of the function displayColors() as 'Red Color' in console?. Here is the code I tried.
const personObj = {
fName: 'John',
lName: 'Doe',
age: 30
};
const carObj = {
type: 'Fiat',
model: 500,
color: 'blue'
};
const workDetailsObj = {
designation: 'Software Engineer',
salary: 30000,
company: 'GE'
};
function displayColors() {
console.log(`Red Color`);
}
let primitiveValue = `Map Object's Contents`;
const mapObj = new Map();
mapObj.set(personObj, 1);
mapObj.set(carObj, 2);
mapObj.set(workDetailsObj, 3);
// mapObj.set(displayFunction, 4);
mapObj.set(primitiveValue, 5);
for (let key of mapObj.keys()) {
console.log(key);
}
But I want the output to be printed as
personObj details:
fName : 'John'
lName : 'Doe'
age : 30
carObj details:
type: 'Fiat'
model: 500
color: 'blue'
workDetailsObj details:
designation: 'Software Engineer'
salary: 30000
company: 'GE'
displayFunction output:
Red Color
primitiveValue value
: Map Object's Contents.
key. Again, variable names are not stored anywhere.