'add in object by for in in javascript
I am new in javascript I have object. When I try to add the city, it doesn't appear in the message. This object show us the detail person. but when I want to put city (forExample) it doesn't show in message
let person = {
name: 'Sam',
age: 30,
employed: true,
is_maried: false
}
and
for (let key in person){
let massage = `key: ${key} and the value is ${person[key]}`;
//this to give you the key name and the value in on line
if (key in person === 'city'){
person.city = 'NY';
}else if (!(key in person !== 'city')){
person.city = 'UK';
}
console.log(massage);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
