Learning Objects || One last thing!
-
See Prints:
Im able to print out everything I need....except for getting a loop to push values into an array then print out each item in the array.
Im trying to loop over the animals.exoticObject array inside of an object to get all of its values.
anybody got any pointers? What am I missing?
Script:
const animals = {}; const newObjects = []; //------------------------------- const dogs = ["dog", "cat", "fish"]; const cats = ["tigger", "felix", "sam"]; const exotic = {"elephant" : "africa", "tiger":"asia", "panda":"china"}; //------------------------------- animals.dogsObject = dogs; animals.catsObject = cats; animals.exoticObject = exotic; //------------------------------- for (k in animals.exoticObject) { Console.print(k); } //------------------------------- for (i = 0; i < animals.exoticObject.length; i++) { newObjects.push(animals.exoticObject[i]); } // Single Items Console.print(animals.exoticObject["elephant"]); Console.print(animals.exoticObject.elephant); Console.print(animals.exoticObject.tiger); // Objects & Arrays Console.print(trace(newObjects)); Console.print(newObjects);
-
@Chazrox said in Learning Objects || One last thing!:
for (i = 0; i < animals.exoticObject.length; i++)
{
newObjects.push(animals.exoticObject[i]);}
isnt it simply this?
for (i = 0; i < animals.exoticObject.length; i++) { newObjects.push(animals.exoticObject[i]); Console.print("Item:" + animals.exoticObject[i]); }