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
  • 211,518
  • 52
  • 313
  • 390
Vishal
  • 23
  • 1
  • 8

3 Answers3

2

Something like this:

data['f name']
davids
  • 6,259
  • 3
  • 29
  • 50
1

Use square bracket notation:

data["f name"]
moonwave99
  • 21,957
  • 3
  • 43
  • 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,986
  • 6
  • 37
  • 59