Welcome, developers, hackers, and watchers!
I'm facing an issue that I can't quite wrap my head around, specifically the part where I need to extract data from one array based on another.
Would merging them help?
Let's take a look at the two arrays:
var teams = ["red", "red", "red", "red", "blue", "blue"];
var scores = [4, 45, 21, 34, 76, 56];
var scoreRed = [];
var scoreBlue = [];
var i;
var scoreBlueIndex;
for (i = 0; i < teams.length; i++){
scoreBlueIndex = teams.indexOf("blue");
scoreBlue = scores[scoreBlueIndex];
}
var ii;
var scoreRedIndex;
for (ii = 0; ii < teams.length; ii++){
scoreRedIndex = teams.indexOf("red");
scoreRed = scores[scoreRedIndex];
}
console.log(scoreRed);
console.log(scoreBlue);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>