I have this code on an angular service. I'm just trying to push an object to an array a given number of times. I'm a bit baffled why this isn't working.
this.createByeArray = function (lengthOfBracket, numberOfPlayers) {
var numberOfByes = lengthOfBracket - numberOfPlayers;
var byeArray = [];
var bye = {
name: "bye",
rank: ""
};
for (var i = 0; i < numberOfByes; i++) {
byeArray.push(bye);
}
console.log(byeArray);
return byeArray;
}
When I log the result, I do seem to get an array with three objects, but I am unable to see either key/value pair on any of the objects when I 'drill down' in the console. Thanks!
Also the parameters I'm passing in are just integers, so that portion of the function is working fine.
*Edit - one more thing I noticed in the console. The final byeArray has a "length" of 0, even though it looks like it has 3 objects on it...
**Edit - Image of my Console added...
**Edit - Here is the code where the function is called on my controller:
$scope.bracketSize = [0, 1, 2, 3, 4, 5, 6, 7];
$scope.players = [object, object, object, object, object];
//each Object is {name: "something", rank: "something}
$scope.byeArray = mainService.createByeArray($scope.bracketSize.length, $scope.players.length);