Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDmitry Kalinchenko
7,365 Pointspush() with a 2d array
I'm having some difficulties figuring out how to push items into a 2d array. I have two 1d arrays and am trying to combine them into a single 2d array. What's wrong with my code?
var criteriaNameArray = [] var criteriaWeightArray = [] var criteriaArray = [] for (let i=0; i=criteriaNameArray.length; i++){ criteriaArray.push([criteriaNameArray[i]][criteriaWeightArray[i]]) }
2 Answers
Tsenko Aleksiev
3,819 PointsSomething like:
var criteriaNameArray = [9, 5, 8, 8, 9, 5, 1];
var criteriaWeightArray = [1,2,3,4,5,6,7,8,9];
var criteriaArray = [[criteriaNameArray],[criteriaWeightArray]];
console.log(criteriaArray);
or I got it wrong?
Dmitry Kalinchenko
7,365 PointsThank you! Much simpler than what I was trying to do.