I am working with an array that contains both numbers and objects. Here is an example:
var array = [0, 0, 1, 0, 2, {type:player, health:100, xp: 0}, 0, 2, 1, 0, {type:weapon, damage:20}]
To dynamically set classes, I loop through the array and store a string in a variable.
Currently, my loop includes a switch statement like this:
for(var i = 0; i < array.length; i++){
var setClass = "";
switch (array[i]) {
case 1:
setClass = "walkable";
break;
case 2:
setClass = "wall";
break;
default:
setClass = "outside"
}
}
Now, I want to enhance this switch statement by checking if the item in the loop is 1) an object and 2) has a specific key/value pair. Specifically, I would like to assign different strings based on the type of the object - whether it's a player or a weapon. How can I achieve this?