I’m having a some trouble with the concat function in javascript. As far as I can tell, I’m using it correctly, but it’s not successfully concatenating the array “value” from the JSON onto the array “currentAbilities”:
$.each(ABILITIES, function(key,value) {
if(key==raceName||(key==className&&(!isAcolyte)))
{
document.getElementById('abs').innerHTML = value[1];
currentAbilities.concat(value);
}
})
The innerHTML setting line shows that the array “value” does exist. Any idea why I’m failing to concat? Value of course comes from a JSON, could that have anything to do with it? I’m afraid I only recently became familiar with $.each and JSON usage and may be doing it wrong.
Assuming the JSON has been parsed, you need to keep a reference to the new Array created by
concat()because the.concat()method does not modify the original…Or just use
.pushwith.applyif you want to modify thecurrentAbilitiesarray…Also, make sure your
raceNameandclassNamevariables are what you expect.