Skip to content Skip to sidebar Skip to footer

Push Is Not A Function Array Population

I want have an array structured as follow: var myMap = {id: ['0', '1'], name:['Op', 'Op2']} Now Op and Op2 is taken by a $.each like this: var myMap = {}; var count = 0 $.each(Glo

Solution 1:

myMap is an object, not an array.

It looks like it should be an array and structured:

var myMap = [
    { id: '0', name: 'Op' },
    { id: '1', name: 'Op2' }
];

Solution 2:

The variable myMap is an object not an array.

Change

var myMap = {id: ['0', '1'], name:['Op', 'Op2']}

to

var myMap = [{id: ['0', '1'], name:['Op', 'Op2']}]

Solution 3:

The straight solution for your problem would be:

myMap.id.push(count);
myMap.name.push(provider['first_name']);

... So that myMap will still contain the values like this:

{id: ['0', '1', '2', '3', '4'... ], name:['Op', 'Op2', 'Op3', 'Op4', 'Op5'...]}

But I do not recommend you this structure. If id and name shall be stored simultaneously, it is recommended that they be linked together. For example: If id values are always unique integers, you could make myMap an array:

var myMap[0]='Op';
var myMap[1]='Op2';
var myMap[2]='Op3';
var myMap[3]='Op4';
...

Post a Comment for "Push Is Not A Function Array Population"