I want to create an array like this:
send[1]['conversation_group_id']=1;
But i get an error that cannot set property conversation_group_id of undefined. What am i doing wrong?
Thanks!
Even though you have initialized send with [], which makes it an array, send[1] will be undefined, you will need to initialize it as an object too before you can set a property inside it. At the moment you are trying to set a property of undefined.
var send = [];
console.log(send[1]);
send[1] = {};
send[1]['conversation_group_id']=1;
console.log(send[1]['conversation_group_id']);
Your data structure is an array of objects. To initialize it, you can also do it this way.
send = [null, {conversation_group_id: 1}]
Nothing wrong with @Dij's answer, but just though it's worth mentioning an alternative on how to initialize the structure you're looking for.
send?send[1]is not an Object, it is not defined.send[1]would have to point to the second element in an array that is an object, but currently it's nothing. If you first didsend[1] = {}and thensend[1]['conversation_group_id'] = 1- it would work.