
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add an element to a javascript object?
JavaScript object notation is like
var car = {name:"Benz", "Brand": "Mercedes", model:"open roof"};
if we need to add the price of the Benz car then the code is as follows.
Example
<html> <body> <p id="demo"></p> <script> var car = {name:"Benz", "Brand": "Mercedes", model:"open roof"}; car.price = "50,000$", car.color = "Black" document.write(JSON.stringify(car)); </script> </body> </html>
Output
{"name":"Benz","Brand":"Mercedes","model":"open roof","price":"50,000$","color":"Black"}
- Related Questions & Answers
- How to add a class name to an element with JavaScript?
- In PHP, how can I add an object element to an array?
- How to add a method to a JavaScript object?
- How to add properties and methods to an object in JavaScript?
- How to add an element in the last of a JavaScript array?
- How to add an event handler to an element in JavaScript HTML DOM?
- How to add an object to a canvas using FabricJS?
- How to add 30 minutes to a JavaScript Date object?
- How to add 2 hours to a JavaScript Date object?
- How to add 10 seconds to a JavaScript date object?
- How to add properties and methods to an existing object in JavaScript?
- How to add, access JavaScript object methods?
- How to add a class to DOM element in JavaScript?
- How to add an event handler to the specified element in JavaScript?
- How to add an active class to the current element with JavaScript?
Advertisements