So I have some arrays (in reality I have about 30-40):
var p1 = ["John", "bio", "john.png"];
var p2 = ["Kate", "bio", "kate.png"];
var p3 = ["Mary", "bio", "mary.png"];
which have the respective information for each person I want to use in my HTML.
I want to add each of these arrays to another array to have a final result of:
var people = [["John", "bio", "john.png"],
["Kate", "bio", "kate.png"],
["Mary", "bio", "mary.png"]];
Is there a way of adding all these p1 , p2, p3 arrays to the people array using a for loop?
I tried this:
for (var i = 1; i <= 30; i++) {
var toPush = "p" + i;
people.push(toPush);
}
But obviously this just creates and pushes strings into the array. How can I get around this?
Thanks!
peoplearray in the first place?var people = [["John", "bio", "john.jpg"], ["Kate", "bio", "kate.jpg"], etc];people = [p1, p2, p3]. If you don't like to type out thirty different variable names, don't use 30 variables in the first place.