0

In the following example, I would like to access each individual object in the given array. I have tested numerous cases, but still I could able to get the values.

enter image description here

enter image description here

casillas
  • 16,351
  • 19
  • 115
  • 215

4 Answers4

3

You can only use the dot to access a property value when the property name is an IdentifierName:

11.2.1 Property Accessors

Properties are accessed by name, using either the dot notation:

MemberExpression . IdentifierName
CallExpression . IdentifierName

or the bracket notation:

MemberExpression [ Expression ]
CallExpression [ Expression ]

But IdentifierNames can't begin with a digit:

7.6 Identifier Names and Identifiers

IdentifierName ::
    IdentifierStart
    IdentifierName IdentifierPart

IdentifierStart ::
    UnicodeLetter
    $
    _
    \ UnicodeEscapeSequence

UnicodeLetter ::
    any character in the Unicode categories “Uppercase letter (Lu)”, “Lowercase letter (Ll)”, “Titlecase letter (Lt)”, “Modifier letter (Lm)”, “Other letter (Lo)”, or “Letter number (Nl)”.

Therefore, you should use the bracket [] notation:

self.dataSeries[0].data[0][0]

Moreover, data[0,1] may not be what you think. The comma operator evaluates both 0 and 1 expressions, and returns the result of the second one:

11.14 Comma Operator ( , )

The production Expression : Expression , AssignmentExpression is evaluated as follows:

  1. Let lref be the result of evaluating Expression.
  2. Call GetValue(lref).
  3. Let rref be the result of evaluating AssignmentExpression.
  4. Return GetValue(rref).

Therefore, data[0,1] is exactly the same as data[1].

Oriol
  • 274,082
  • 63
  • 437
  • 513
2

self.dataSeries[0].data[0][0]

Your first attempt was close, but you can't access array indexes with the dot notation, and must use the array notation

PhilVarg
  • 4,762
  • 2
  • 19
  • 37
1

You need to access 0, 450 and 450? Cant you just do self.dataSeries[0].data[0][1]?

thefourtheye
  • 233,700
  • 52
  • 457
  • 497
zeratulmdq
  • 1,484
  • 16
  • 15
1

You can access your data like this

self.dataSeries[0].data[0][0]

Pattern is

self.dataSeries[parentIndex].data[childIndex][grandChildIndex]
Anik Islam Abhi
  • 25,137
  • 8
  • 58
  • 80