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
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
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
.
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.