Basically, I am trying to list an array in the console like this, I will give an example.
config.json
{
Names: [
"Stewart",
"Bob",
"Kevin"
]
}
And then the console would print out once called in a JS file
- Stewart
- Bob
- Kevin
And also if I were to add more code to the array it would keep on listing numbers like that.
I haven’t tried anything yet, I am mostly new to this.
3
Answers
This is how you can do this
run a forEach of your Names array inside your object like this
or the alternative for loop
To list the contents of an array in JS, you can use a loop.
There are few concepts here worth looking into to understand how the example loop works:
console.log(names[index])