How to access object property with invalid characters
In JavaScript, object properties can be accessed by dot notation or bracket notation. Dot notation is often cleaner, but has restrictions. As you have noticed, your property contains an invalid character and therefore can't be accessed via dot notation. The solution, then, is to access the property using bracket notation like this: total['ga:newVisits']
so that your complete code will be {{total['ga:newVisits']}}
. Live demo here (click).
Another nice feature about bracket notation is that it allows you to use a variable name as a property:
var myObj {
bar: '123'
};
var foo = 'bar';
console.log(myObj[foo]); //logs '123'
How to access object propety when it has special characters in PHP
You need add the property into "{}".
$b2cUser->{'@odata.nextLink'}
How to access object properties with names with special characters? (like quotes)
Are you sure something else isn't going on with your object? Your first example listed worked for me. See screenshot of an object I made with an imported CSV below -
How to access property of javascript object with special character in property name
AngularJS does nothing special here. Refer to the regular rules for referencing properties in a javascript object.
In a controller: console.log($scope.data['Handedness;'])
In a view: {{ data['Handedness;'] }}
How do I access object attributes that contain special characters?
This should work: const price = data['Global Quote']['05. price']
How to destructure object properties with key names that are invalid variable names?
const data = { "key-with-dash": ["BAZ"]}
const {"key-with-dash": foo} = data;
console.log("foo", foo);
Related Topics
Ajax Call and Clean JSON But Syntax Error: Missing ; Before Statement
JavaScript Design Pattern: Difference Between Module Pattern and Revealing Module Pattern
Javascript/Jquery: Set Values (Selection) in a Multiple Select
Trying to Use the Domparser with Node Js
JavaScript Library for Human-Friendly Relative Date Formatting
How to Serve a File for Download with Angularjs or JavaScript
Replacing &Nbsp; from JavaScript Dom Text Node
Window.Onload VS. Body.Onload VS. Document.Onready
Jquery: How to Get the Event Object in an Event Handler Function Without Passing It as an Argument
How to Catch Exceptions Thrown in a JavaScript Async Callback
How to Get the Back Button to Work with an Angularjs Ui-Router State MAChine
Example of a Circular Reference in JavaScript
Checking If Image Does Exists Using JavaScript
How to Get the First Element of an Array