tags:

views:

135

answers:

3

Hi

I have 3 arrays meat,veg and sauce, I was wondering how to add their values to a new array called food.

thanks for any help

+10  A: 

You can use the concat function.

var food = meat.concat(veg,sauce);
CMS
how can I do that?
Just call concat on one of the arrays with the other arrays as arguments. It will return the merged array.
Dykam
A: 

You could use an object:

var food = {
    meat: meat,
    veg: veg,
    sauce: sauce
};

Then you can access the arrays with food.meat, food.veg and food.sauce.

Gumbo
A: 

You can use "concat()":

var meat = ["m","e","a","t"]; var veg = ["v","e","g"]; var sauce = ["s","a","u","c","e"]; var food = meat.concat(veg, sauce); alert(food);

I hope this is what you want.

Ramiz Uddin