Kyemme
Kyemme

Reputation: 25

Array within an array in jQuery

Is this array with in array declaration correct? and if it is correct how can I output or atleast alert all the contents in the chkArray?

var chkArray = { tv_type[],screen_size[],connectivity[],features[]};
var tv_type = [];
var screen_size = [];
var connectivity = [];
var features = [];

Upvotes: -1

Views: 75

Answers (3)

midhun
midhun

Reputation: 157

You can not declare a multidimensional array like this

Possible solution will be

var arrayA = [];
var arrayB = [];
var arrayC = []; 
var arrayTotal = [arrayA,arrayB,arrayC];

and you can use

console.log(arrayTotal)

to print the array in console

Upvotes: 0

Girish
Girish

Reputation: 12117

Define array according variable scope

var tv_type = [];
var screen_size = [];
var connectivity = [];
var features = [];

//incorrect syntax
/*var chkArray = { tv_type[],screen_size[],connectivity[],features[]};*/

//change to 
var chkArray = [tv_type,screen_size,connectivity,features];

For debug Try this

alert(JSON.stringify(chkArray))

OR

console.log(chkArray)

Upvotes: 0

valanto
valanto

Reputation: 911

I think you want an object with arrays in it even though you are asking for arrays in array. It's more meaningful for your usecase. A bit like this

var chkArray = {
    tv_type: [],
    screen_size: [],
    connectivity: [],
    features: []
}

To access them you can say:

chkArray.tv_type[index]

And push items:

chkArray.tv_type.push("LCD");

Upvotes: 0

Related Questions