Kirk Strobeck
Kirk Strobeck

Reputation: 18589

Javascript: Dot notation for dashes?

How would I write this in dot notation?

req.headers['x-forwarded-for']

This does not work

req.headers.xForwardedFor

Upvotes: 0

Views: 430

Answers (2)

Bergi
Bergi

Reputation: 664425

You cannot, since for dot notation the property name would need to be a valid identifier name which must not contain dashes.

Upvotes: 3

dave
dave

Reputation: 64657

You wouldn't, you can't access an object property with dashes in it using dot notation.

Upvotes: 2

Related Questions