javascript - JS - Adding arrays to an array with variable name manipulation using for -
so have arrays (in reality have 30-40):
var p1 = ["john", "bio", "john.png"]; var p2 = ["kate", "bio", "kate.png"]; var p3 = ["mary", "bio", "mary.png"];
which have respective information each person want use in html.
i want add each of these arrays array have final result of:
var people = [["john", "bio", "john.png"], ["kate", "bio", "kate.png"], ["mary", "bio", "mary.png"]];
is there way of adding these p1
, p2
, p3
arrays people
array using loop?
i tried this:
for (var = 1; <= 30; i++) { var topush = "p" + i; people.push(topush); }
but creates , pushes strings array. how can around this?
thanks!
you should start people array instead of creating individual variables each array create arrays this:
var people = new array(); people.push(["john", "bio", "john.png"]); people.push(["kate", "bio", "kate.png"]);
etc...
Comments
Post a Comment