Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

85
Views
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);
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

let person = {
  name: 'Sam',
  age: 30,
  employed: true,
  is_maried: false
}

if (person.city) {
  person.city = "NY";
} else {
  person.city = "UK";
}

console.log(person);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!