-3

I am trying to pass an array through jQuery's ajax. The problem is that when I try to pass the array created in JavaScript to JSON, it returns something empty. I even try console.log, but when I try to convert it to JSON there is nothing. Here is a representation of how I do it:

var data = [];
data['name'] = 'test';
data['mail'] = 'test';
data['pass'] = 'test';
console.log(JSON.stringify(data)); // result []
Nebula
  • 6,614
  • 4
  • 20
  • 40
Tprogramer
  • 85
  • 1
  • 14

1 Answers1

1

Every array is an object. You are assigning object properties with the data['name'] = 'test' syntax. Arrays are indexed with integers and they "must" be in sequence. try a[0] = 'foo'. or Array.push