{"id":199167,"date":"2023-10-09T04:15:24","date_gmt":"2023-10-09T04:15:24","guid":{"rendered":"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/"},"modified":"2023-10-09T04:15:24","modified_gmt":"2023-10-09T04:15:24","slug":"how-to-add-key-and-value-in-an-object-in-javascript","status":"publish","type":"post","link":"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/","title":{"rendered":"How to add key and value in an object in JavaScript?"},"content":{"rendered":"<p>Adding key and value pairs to an object in JavaScript is a common task when working with data structures. Objects in JavaScript are collections of key-value pairs, where keys are unique strings and values can be any data type. There are a few different ways to add key and value pairs to an object in JavaScript. Let&#8217;s explore some of these methods.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_62 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#How_to_add_key_and_value_in_an_object_in_JavaScript_using_dot_notation\" title=\"How to add key and value in an object in JavaScript using dot notation?\">How to add key and value in an object in JavaScript using dot notation?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#How_to_add_key_and_value_in_an_object_in_JavaScript_using_bracket_notation\" title=\"How to add key and value in an object in JavaScript using bracket notation?\">How to add key and value in an object in JavaScript using bracket notation?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#How_to_add_multiple_key_and_value_pairs_in_an_object_in_JavaScript\" title=\"How to add multiple key and value pairs in an object in JavaScript?\">How to add multiple key and value pairs in an object in JavaScript?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#Can_I_add_key_and_value_pairs_to_an_object_using_Objectassign_method\" title=\"Can I add key and value pairs to an object using Object.assign() method?\">Can I add key and value pairs to an object using Object.assign() method?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#How_to_add_key_and_value_in_an_object_in_JavaScript_using_Objectassign_method\" title=\"How to add key and value in an object in JavaScript using Object.assign() method?\">How to add key and value in an object in JavaScript using Object.assign() method?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#Can_I_add_key_and_value_pairs_to_an_object_using_spread_syntax_in_JavaScript\" title=\"Can I add key and value pairs to an object using spread syntax in JavaScript?\">Can I add key and value pairs to an object using spread syntax in JavaScript?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#How_to_add_key_and_value_in_an_object_in_JavaScript_using_spread_syntax\" title=\"How to add key and value in an object in JavaScript using spread syntax?\">How to add key and value in an object in JavaScript using spread syntax?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#Can_I_add_key_and_value_pairs_to_an_object_in_JavaScript_using_ES6_ObjectdefineProperty_method\" title=\"Can I add key and value pairs to an object in JavaScript using ES6 Object.defineProperty() method?\">Can I add key and value pairs to an object in JavaScript using ES6 Object.defineProperty() method?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#How_to_add_key_and_value_in_an_object_in_JavaScript_using_ObjectdefineProperty_method\" title=\"How to add key and value in an object in JavaScript using Object.defineProperty() method?\">How to add key and value in an object in JavaScript using Object.defineProperty() method?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#Can_I_add_key_and_value_pairs_to_an_object_in_JavaScript_using_ES6_computed_property_names\" title=\"Can I add key and value pairs to an object in JavaScript using ES6 computed property names?\">Can I add key and value pairs to an object in JavaScript using ES6 computed property names?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#How_to_add_key_and_value_in_an_object_in_JavaScript_using_ES6_computed_property_names\" title=\"How to add key and value in an object in JavaScript using ES6 computed property names?\">How to add key and value in an object in JavaScript using ES6 computed property names?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#Can_I_add_key_and_value_pairs_to_an_object_in_JavaScript_using_ES6_Objectentries_method\" title=\"Can I add key and value pairs to an object in JavaScript using ES6 Object.entries() method?\">Can I add key and value pairs to an object in JavaScript using ES6 Object.entries() method?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#How_to_add_key_and_value_in_an_object_in_JavaScript_using_ES6_Objectentries_method\" title=\"How to add key and value in an object in JavaScript using ES6 Object.entries() method?\">How to add key and value in an object in JavaScript using ES6 Object.entries() method?<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"How_to_add_key_and_value_in_an_object_in_JavaScript_using_dot_notation\"><\/span>How to add key and value in an object in JavaScript using dot notation?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>One of the simplest ways to add a key and value pair to an object in JavaScript is by using dot notation. You can add a new key and value to an object using the following syntax:<\/p>\n<p>&#8220;`javascript<br \/>\nconst myObject = {};<br \/>\nmyObject.newKey = &#8216;Some value&#8217;;<br \/>\n&#8220;`<\/p>\n<p>In this example, we created an empty object called `myObject` and added a new key called `newKey` with a value of `&#8217;Some value&#8217;`.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_to_add_key_and_value_in_an_object_in_JavaScript_using_bracket_notation\"><\/span>How to add key and value in an object in JavaScript using bracket notation?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Another way to add a key and value pair to an object in JavaScript is by using bracket notation. This method is useful when you have a dynamic key or when the key contains special characters. Here&#8217;s how you can add a new key and value using bracket notation:<\/p>\n<p>&#8220;`javascript<br \/>\nconst myObject = {};<br \/>\nmyObject[&#8216;newKey&#8217;] = &#8216;Some value&#8217;;<br \/>\n&#8220;`<\/p>\n<p>Using bracket notation allows you to add keys that are not valid JavaScript identifiers, such as keys with spaces or special characters.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_to_add_multiple_key_and_value_pairs_in_an_object_in_JavaScript\"><\/span>How to add multiple key and value pairs in an object in JavaScript?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To add multiple key-value pairs to an object in JavaScript, you can simply chain together the dot or bracket notation methods. Here&#8217;s an example of adding multiple key-value pairs:<\/p>\n<p>&#8220;`javascript<br \/>\nconst myObject = {};<br \/>\nmyObject.key1 = &#8216;Value 1&#8217;;<br \/>\nmyObject[&#8216;key2&#8217;] = &#8216;Value 2&#8217;;<br \/>\nmyObject.key3 = &#8216;Value 3&#8217;;<br \/>\n&#8220;`<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Can_I_add_key_and_value_pairs_to_an_object_using_Objectassign_method\"><\/span>Can I add key and value pairs to an object using Object.assign() method?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Yes, you can use the `Object.assign()` method to add key and value pairs to an object in JavaScript. This method copies all enumerable own properties from one or more source objects to a target object.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_to_add_key_and_value_in_an_object_in_JavaScript_using_Objectassign_method\"><\/span>How to add key and value in an object in JavaScript using Object.assign() method?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You can use the `Object.assign()` method to add key and value pairs to an object like this:<\/p>\n<p>&#8220;`javascript<br \/>\nconst target = {};<br \/>\nconst source = { key: &#8216;value&#8217; };<br \/>\nObject.assign(target, source);<br \/>\n&#8220;`<\/p>\n<p>In this example, the `key` and `value` from the `source` object are added to the `target` object.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Can_I_add_key_and_value_pairs_to_an_object_using_spread_syntax_in_JavaScript\"><\/span>Can I add key and value pairs to an object using spread syntax in JavaScript?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Yes, you can use the spread syntax to add key and value pairs to an object in JavaScript. The spread syntax allows you to merge multiple objects into one.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_to_add_key_and_value_in_an_object_in_JavaScript_using_spread_syntax\"><\/span>How to add key and value in an object in JavaScript using spread syntax?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You can add key and value pairs to an object using spread syntax like this:<\/p>\n<p>&#8220;`javascript<br \/>\nconst target = { key1: &#8216;value1&#8217; };<br \/>\nconst source = { key2: &#8216;value2&#8217; };<br \/>\nconst combined = { &#8230;target, &#8230;source };<br \/>\n&#8220;`<\/p>\n<p>In this example, the `key2` and `value2` from the `source` object are added to the `target` object, creating a new object called `combined`.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Can_I_add_key_and_value_pairs_to_an_object_in_JavaScript_using_ES6_ObjectdefineProperty_method\"><\/span>Can I add key and value pairs to an object in JavaScript using ES6 Object.defineProperty() method?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Yes, you can use the `Object.defineProperty()` method to add key and value pairs to an object in JavaScript. This method allows you to define a new property directly on an object or modify an existing property.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_to_add_key_and_value_in_an_object_in_JavaScript_using_ObjectdefineProperty_method\"><\/span>How to add key and value in an object in JavaScript using Object.defineProperty() method?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You can add key and value pairs to an object using `Object.defineProperty()` method like this:<\/p>\n<p>&#8220;`javascript<br \/>\nconst myObject = {};<br \/>\nObject.defineProperty(myObject, &#8216;newKey&#8217;, {<br \/>\n  value: &#8216;Some value&#8217;,<br \/>\n  writable: true,<br \/>\n  enumerable: true,<br \/>\n  configurable: true<br \/>\n});<br \/>\n&#8220;`<\/p>\n<p>In this example, we defined a new property called `newKey` on the `myObject` object with a value of `&#8217;Some value&#8217;`.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Can_I_add_key_and_value_pairs_to_an_object_in_JavaScript_using_ES6_computed_property_names\"><\/span>Can I add key and value pairs to an object in JavaScript using ES6 computed property names?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Yes, you can use ES6 computed property names to add key and value pairs to an object in JavaScript. Computed property names allow you to dynamically set the key of an object property.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_to_add_key_and_value_in_an_object_in_JavaScript_using_ES6_computed_property_names\"><\/span>How to add key and value in an object in JavaScript using ES6 computed property names?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You can add key and value pairs to an object using ES6 computed property names like this:<\/p>\n<p>&#8220;`javascript<br \/>\nconst key = &#8216;newKey&#8217;;<br \/>\nconst myObject = { [key]: &#8216;Some value&#8217; };<br \/>\n&#8220;`<\/p>\n<p>In this example, we used a variable `key` to dynamically set the key of the new property on the `myObject` object.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Can_I_add_key_and_value_pairs_to_an_object_in_JavaScript_using_ES6_Objectentries_method\"><\/span>Can I add key and value pairs to an object in JavaScript using ES6 Object.entries() method?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Yes, you can use the `Object.entries()` method to add key and value pairs to an object in JavaScript. This method returns an array of a given object&#8217;s string key-value pairs.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"How_to_add_key_and_value_in_an_object_in_JavaScript_using_ES6_Objectentries_method\"><\/span>How to add key and value in an object in JavaScript using ES6 Object.entries() method?<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You can add key and value pairs to an object using `Object.entries()` method like this:<\/p>\n<p>&#8220;`javascript<br \/>\nconst myObject = Object.fromEntries(<br \/>\n  Object.entries({ key: &#8216;value&#8217; }).concat([[&#8216;newKey&#8217;, &#8216;Some value&#8217;]])<br \/>\n);<br \/>\n&#8220;`<\/p>\n<p>In this example, we used `Object.entries()` to get the key-value pairs of the object, concatenated a new key-value pair, and then created a new object using `Object.fromEntries()`.<\/p>\n<p>By using these methods, you can easily add key and value pairs to objects in JavaScript, making your code more dynamic and flexible. Whether you prefer dot notation, bracket notation, Object.assign(), spread syntax, Object.defineProperty(), ES6 computed property names, or Object.entries(), there are multiple ways to achieve the same result in JavaScript. Choose the method that best suits your coding style and requirements.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Adding key and value pairs to an object in JavaScript is a common task when working with data structures. Objects in JavaScript are collections of key-value pairs, where keys are unique strings and values can be any data type. There are a few different ways to add key and value pairs to an object in &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"How to add key and value in an object in JavaScript?\" class=\"read-more button\" href=\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#more-199167\">Read more<span class=\"screen-reader-text\">How to add key and value in an object in JavaScript?<\/span><\/a><\/p>\n","protected":false},"author":51,"featured_media":107420,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[86279],"tags":[],"class_list":["post-199167","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learn","no-featured-image-padding"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to add key and value in an object in JavaScript?<\/title>\n<meta name=\"description\" content=\"Adding key and value pairs to an object in JavaScript is a common task when working with data structures. Objects in JavaScript are collections of\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to add key and value in an object in JavaScript?\" \/>\n<meta property=\"og:description\" content=\"Adding key and value pairs to an object in JavaScript is a common task when working with data structures. Objects in JavaScript are collections of\" \/>\n<meta property=\"og:url\" content=\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/synchronyfinancial\" \/>\n<meta property=\"article:published_time\" content=\"2023-10-09T04:15:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"500\" \/>\n\t<meta property=\"og:image:height\" content=\"164\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Adam Forbes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@synchrony\" \/>\n<meta name=\"twitter:site\" content=\"@synchrony\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Adam Forbes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/\"},\"author\":{\"name\":\"Adam Forbes\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/88cd882dfb29a6b147bc0ea26dc84060\"},\"headline\":\"How to add key and value in an object in JavaScript?\",\"datePublished\":\"2023-10-09T04:15:24+00:00\",\"dateModified\":\"2023-10-09T04:15:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/\"},\"wordCount\":947,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#organization\"},\"articleSection\":[\"Learn\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/\",\"url\":\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/\",\"name\":\"How to add key and value in an object in JavaScript?\",\"isPartOf\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#website\"},\"datePublished\":\"2023-10-09T04:15:24+00:00\",\"dateModified\":\"2023-10-09T04:15:24+00:00\",\"description\":\"Adding key and value pairs to an object in JavaScript is a common task when working with data structures. Objects in JavaScript are collections of\",\"breadcrumb\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/namso-gen.co\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to add key and value in an object in JavaScript?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#website\",\"url\":\"https:\/\/namso-gen.co\/blog\/\",\"name\":\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\",\"description\":\"In Namso gen blog you can get many tips regarding to Credit cards, VCC, Credit card security etc. You can generate credit cards by using Namso-gen.co\",\"publisher\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/namso-gen.co\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#organization\",\"name\":\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\",\"url\":\"https:\/\/namso-gen.co\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png\",\"contentUrl\":\"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png\",\"width\":500,\"height\":164,\"caption\":\"Namso Gen Blog - Free Credit Card Generator [100% Valid]\"},\"image\":{\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/synchronyfinancial\",\"https:\/\/twitter.com\/synchrony\",\"https:\/\/www.youtube.com\/synchronyfinancial\",\"https:\/\/www.instagram.com\/synchrony\",\"https:\/\/www.linkedin.com\/company\/synchrony-financial\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/88cd882dfb29a6b147bc0ea26dc84060\",\"name\":\"Adam Forbes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g\",\"caption\":\"Adam Forbes\"},\"description\":\"Guest author Adam Forbes has meticulously crafted and revised this article to the best of their knowledge and understanding. Readers are strongly advised to exercise caution, verify information independently, and rely on their own judgment when considering the information provided. Read more articles on Namso Gen here.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to add key and value in an object in JavaScript?","description":"Adding key and value pairs to an object in JavaScript is a common task when working with data structures. Objects in JavaScript are collections of","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/","og_locale":"en_US","og_type":"article","og_title":"How to add key and value in an object in JavaScript?","og_description":"Adding key and value pairs to an object in JavaScript is a common task when working with data structures. Objects in JavaScript are collections of","og_url":"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/","og_site_name":"Namso Gen Blog - Free Credit Card Generator [100% Valid]","article_publisher":"https:\/\/www.facebook.com\/synchronyfinancial","article_published_time":"2023-10-09T04:15:24+00:00","og_image":[{"width":500,"height":164,"url":"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png","type":"image\/png"}],"author":"Adam Forbes","twitter_card":"summary_large_image","twitter_creator":"@synchrony","twitter_site":"@synchrony","twitter_misc":{"Written by":"Adam Forbes","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#article","isPartOf":{"@id":"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/"},"author":{"name":"Adam Forbes","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/88cd882dfb29a6b147bc0ea26dc84060"},"headline":"How to add key and value in an object in JavaScript?","datePublished":"2023-10-09T04:15:24+00:00","dateModified":"2023-10-09T04:15:24+00:00","mainEntityOfPage":{"@id":"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/"},"wordCount":947,"commentCount":0,"publisher":{"@id":"https:\/\/namso-gen.co\/blog\/#organization"},"articleSection":["Learn"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/","url":"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/","name":"How to add key and value in an object in JavaScript?","isPartOf":{"@id":"https:\/\/namso-gen.co\/blog\/#website"},"datePublished":"2023-10-09T04:15:24+00:00","dateModified":"2023-10-09T04:15:24+00:00","description":"Adding key and value pairs to an object in JavaScript is a common task when working with data structures. Objects in JavaScript are collections of","breadcrumb":{"@id":"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/namso-gen.co\/blog\/how-to-add-key-and-value-in-an-object-in-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/namso-gen.co\/blog\/"},{"@type":"ListItem","position":2,"name":"How to add key and value in an object in JavaScript?"}]},{"@type":"WebSite","@id":"https:\/\/namso-gen.co\/blog\/#website","url":"https:\/\/namso-gen.co\/blog\/","name":"Namso Gen Blog - Free Credit Card Generator [100% Valid]","description":"In Namso gen blog you can get many tips regarding to Credit cards, VCC, Credit card security etc. You can generate credit cards by using Namso-gen.co","publisher":{"@id":"https:\/\/namso-gen.co\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/namso-gen.co\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/namso-gen.co\/blog\/#organization","name":"Namso Gen Blog - Free Credit Card Generator [100% Valid]","url":"https:\/\/namso-gen.co\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png","contentUrl":"https:\/\/namso-gen.co\/blog\/wp-content\/uploads\/2020\/07\/namso-gen-logo.png","width":500,"height":164,"caption":"Namso Gen Blog - Free Credit Card Generator [100% Valid]"},"image":{"@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/synchronyfinancial","https:\/\/twitter.com\/synchrony","https:\/\/www.youtube.com\/synchronyfinancial","https:\/\/www.instagram.com\/synchrony","https:\/\/www.linkedin.com\/company\/synchrony-financial"]},{"@type":"Person","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/88cd882dfb29a6b147bc0ea26dc84060","name":"Adam Forbes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/namso-gen.co\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=mm&r=g","caption":"Adam Forbes"},"description":"Guest author Adam Forbes has meticulously crafted and revised this article to the best of their knowledge and understanding. Readers are strongly advised to exercise caution, verify information independently, and rely on their own judgment when considering the information provided. Read more articles on Namso Gen here."}]}},"_links":{"self":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/posts\/199167","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/users\/51"}],"replies":[{"embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/comments?post=199167"}],"version-history":[{"count":0,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/posts\/199167\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/media\/107420"}],"wp:attachment":[{"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/media?parent=199167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/categories?post=199167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/namso-gen.co\/blog\/wp-json\/wp\/v2\/tags?post=199167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}