1

Suppose if a object has parameters var data={"f name":"vishal"} and i want to access parameter "f name" in javascript. I know that there should not be space in parameters of a object but if it has space in it then how can i read it.

georg
  • 204,715
  • 48
  • 286
  • 369
Vishal
  • 23
  • 1
  • 8

3 Answers3

2

Something like this:

data['f name']
davids
  • 6,049
  • 3
  • 27
  • 46
1

Use square bracket notation:

data["f name"]
moonwave99
  • 20,750
  • 2
  • 41
  • 64
1

Spaces in attribute names are perfectly OK in JavaScript. You reference them by the

object["param name"] 

syntax. Moreover, any UTF8 character, except for control characters, are valid in attribute names.

marekful
  • 14,178
  • 5
  • 35
  • 56