I've minimally modified your existing code as I thought it would be helpful for you to learn.
Explanation
allQuotes had not been initialised (assigned a value). I've assigned it an empty array.
.map returns an array whose items will be the return value from .map's callback function (the function we pass as an argument to .map). The callback function is called as many times as there are items on the array (array.length).
I've made it so every item of quotesList ({quote: ..., author: ...}) is added to the allQuotes array.
Finally, in next_quote you can see how we step into the item of the allQuotes array with allQuotes[counter] - which returns the {quote: ..., name: ...}. Then, you can see how we further step in it with .quote or .author - retrieving the values of these properties.
Once the counter is the same as the number of quotes, it resets to zero.
Code
let quotesList = [
{
"quote": "Whether you think you can or you think you can’t, you’re right.",
"author": "—Mother Teresa",
},
{
"quote": "Act as if what you do makes a difference. It does.",
"author": "—William James",
},
{
"quote": "What you get by achieving your goals is not as important as what you become by achieving your goals.",
"author": "—Zig Ziglar",
},
];
var counter = 0;
let allQuotes = [];
quotesList.map((item, index, array) => {
allQuotes[index] = item;
})
function next_quote() {
console.log(allQuotes[counter].quote + '\n' + allQuotes[counter].author);
counter += 1;
if (counter === allQuotes.length) {
counter = 0;
}
}
function start() {
console.log(allQuotes[counter].quote + '\n' + allQuotes[counter].author);
counter += 1;
setInterval(next_quote, 2000);
}
start();
Refactored into one function - happy to explain if you want
let quotesList = [
{
"quote": "Whether you think you can or you think you can’t, you’re right.",
"author": "—Mother Teresa",
},
{
"quote": "Act as if what you do makes a difference. It does.",
"author": "—William James",
},
{
"quote": "What you get by achieving your goals is not as important as what you become by achieving your goals.",
"author": "—Zig Ziglar",
},
];
function start() {
let quoteCounter = 0;
function currentQuote() {
console.log(quotesList[quoteCounter].quote + '\n' + quotesList[quoteCounter].author);
}
for (; ; quoteCounter++) {
if (quoteCounter === 0) {
currentQuote();
continue;
}
setInterval(function() {
currentQuote();
quoteCounter++;
quoteCounter === quotesList.length ? quoteCounter = 0 : null
}, 2000);
break;
}
}
start();
mapfunction incorrectly. It's overridingallQuoteseach interation..author::before { content: '- '; }(you'd have to put a<span class="author">around the author name in your innerHTML)