-1

so if for example i have a object called Persona and it has the followed property

var person = { name: 'Derwyn', age: '40', occupation: student };

i would like to check all those properties in that object and if the object has a name (in this case it has) i will take that name (Derwyn) and use it in a string to form the sentences

hello my name is Derwyn, im 40 years old and im currently a student.

i tried a for in and a "hasOwnProperty" but after checking it only shows true or false, i need to hold the property in a variable

1 Answers1

-1
if (person.name) {
  console.log(`Hello my name is ${person.name}`)
}
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
noviceGuru
  • 125
  • 1
  • 6
  • Your answer could be improved by adding more information on what the code does and how it helps the OP. – Tyler2P Feb 12 '23 at 13:33