How can you add a new property to a JavaScript object

  • a) By using the Object.assign() method.
  • b) By using the Object.addProperty() method.
  • c) By simply assigning a value to a new property name.
  • d) By using the addProperty() function.
You can add a new property to a JavaScript object by simply assigning a value to a new property name. For example, myObject.newProperty = 'some value';. While you can use methods like Object.assign() to copy properties from one object to another, it's not used for adding new properties. There's no Object.addProperty() or addProperty() method.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *