
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to access an object having spaces in the object’s key using JavaScript?
In this article, you will understand how to access an object having spaces in the object’s key using JavaScript. In such cases, we use bracket notation ‘[]’ to access objects or we use dot notation(.) to access objects. Let’s see a few examples below.
Example 1
In this example, let's use the bracket notation[] to access objects.
console.log("The input object is a key value pair with key as firstName and value as Joseph"); const inputObject = {'firstName': 'Joseph'}; console.log("Using bracket notation to access value") console.log(inputObject['firstName']); console.log("Using bracket notation to change the value to Alice") inputObject['firstName'] = 'Alice'; console.log(inputObject);
Explanation
Step 1 − Define a key-value object and declare the values
Step 2 − Use the bracket notation to access the value of the object. Display the result.
Step 3 − Use the bracket notation to change the value. Display the new value.
Example 2
console.log("The input object is a key value pair with key as firstName and value as Joseph"); const inputObject = {'firstName': 'Joseph'}; console.log("Using dot notation to access value") console.log(inputObject.firstName);
Explanation
Step 1 − Define a key-value object and declare the values.
Step 2 − Use the dot notation to access the value of the object. Display the result.
- Related Articles
- How to access an object value using variable key in JavaScript?
- How to convert Object’s array to an array using JavaScript?
- How to access the first value of an object using JavaScript?
- How to access an object through another object in JavaScript?
- How to access cookies using document object in JavaScript?
- How to create an object and access its properties in JavaScript?
- How to access a JavaScript object using its own prototype?
- JavaScript: How to Create an Object from Key-Value Pairs
- How to change an object Key without changing the original array in JavaScript?
- How to add, access JavaScript object methods?
- How to modify key values in an object with JavaScript and remove the underscore?
- How to add, access, delete, JavaScript object properties?
- How to create a third object from two objects using the key values in JavaScript?
- How to get key name when the value contains empty in an object with JavaScript?
- How to set a String as a key for an object - JavaScript?

Advertisements