1

Hi I have an object that I have filled from data in a CSV file.

One of my ids is called "Disk_Usage(MB)"

I try using my object.Disk_Usage(MB) but receive an error because javascript thinks disk usage is a function and that MB is a variable.

I receive a reference error on the console saying MB is not defined.

4

3 Answers 3

6

Use array/bracket notation:

var propertyValue = yourObject['Disk_Usage(MB)']; 

If you're wondering why you need to do this and/or "but my object isn't an array!," I would suggest having a read through the "Working with objects" article over at MDN.

Sign up to request clarification or add additional context in comments.

Comments

3

Do this:

object['Disk_Usage(MB)'] 

Read this

Comments

0

Although object member access can be performed like this:

var o = { 'abc': 123 }; console.log(o.abc); 

it is often more convenient to use array-bracket notation:

console.log(o['abc']); 

This is one of those times when you must do so, since your key has characters in it that make it an illegal identifier. You must provide it as a string.

Personally, as a matter of consistency, I try to stick to the array-bracket notation all the time.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.