conan conan - 4 months ago 7
jQuery Question

Trying to create an array based on this situation, jquery or javascript

I am trying to create a multidimensional array. something like following code, 44 and 45 is the key. When var pro is 44, I want to get 'onset, frequency' and then split them by .split(','). how should I write this array. Appreciate.



var pro = 44;
var global = [
44 : ["onset",'frequency'],
45 : ["onset"]
]




Answer

First of you have to convert your global array in object like below. And then you can get value for the keys.

{"44":["onset","frequency"],"45":["onset"]}

please refer below snippet for more understanding.

var pro = 44;
var global = {"44":["onset","frequency"],"45":["onset"]};
console.log(global[44]);
console.log(global[44].join(','));