let condiments = ['Ketchup', 'Mustard', 'Soy Sauce', 'Sriracha'];
const utensils = ['Fork', 'Knife', 'Chopsticks', 'Spork'];
condiments.push('bbq','Secret Family Recipe');
console.log(condiments);
Here is the exercise: Arrays
For some reason actually logging to console is not working with the same strategy as just using a string:
The below is an example of a string:
newYearsResolutions.push('eat good food', 'laugh!');
awetek
#2
I think its because newYearsResolutions is undefined??? let newYears = ///// newYears.push();
I answered my own question:grin:
mtf
#4
Two strings, actually. When pushed to the array they will be separate elements.
When we print an array, such as,
console.log(condiments)
what gets printed is a string representation of the array and its structure…
[ 'Ketchup', 'Mustard', 'Soy Sauce', 'Sriracha' ]
We can also extract the elements in a single string…
console.log(condiments.toString())
Ketchup,Mustard,Soy Sauce,Sriracha
Ideally, logging an array is done by iterating over the elements and printing each one, in turn.
condiments.forEach(x => console.log(x))
Ketchup
Mustard
Soy Sauce
Sriracha
Not sure if this addresses your question. Please elaborate further if not.
3 Likes
I was able to answer through trial and error but it looked like you use the same console.log process.
2 Likes
awetek
#6
i was wrong lol newYears = [‘La’, ‘La’];
newYears.push(‘lo’);
console.log(newYears);
system
closed
#7
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.