0

I have a simple function declared like this:

foo(data){
    ....
}

I am trying to call the function by sending it a key value like so:

foo({
    A : {{1, 2}, {3, 4}}
});


But I keep getting the following error from my ide (netbeans)
Expected indent but found {
        A : {{1, 2}, {3, 4}}
             ^

Expected an operand but found ,
        A : {{1, 2}, {3, 4}}
                   ^

What am I doing wrong?

Krimson
  • 7,386
  • 11
  • 60
  • 97
  • 2
    Where did you get the `{1, 2}` syntax from? That doesn't exist in JS. Arrays: `[1,2,3]`, objects: `{foo: 42}`. I recommend to read a tutorial to learn about basic JS syntax: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Predefined_Core_Objects#Creating_an_Array, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects#Using_object_initializers – Felix Kling Jun 09 '14 at 00:42
  • FYI, if you want an object that implements sets in javascript, see [here](http://stackoverflow.com/questions/7958292/mimicking-sets-in-javascript/7958422#7958422). – jfriend00 Jun 09 '14 at 02:06

1 Answers1

0

A : {{1, 2}, {3, 4}} doesn't make any sense. In JavaScript {} creates a key-value store, also known as a JavaScript object. Every element inside of a JavaScript object must be a key-value pair. To store a simple list/array, use []

foo({
    A : [[1, 2], [3, 4]]
});
Jephron
  • 2,652
  • 1
  • 23
  • 34