1

How to add a counter to items in a quick.db table?

db.set('myItems', ['Blue', 'red'])
const content = db.get('myItems')
channel.send(content)

I get the output as:

Blue
Black
Red

I expect the output to be like this:

1 Blue
2 Black
3 Red

How to make the output appear with numbers? P.S Not adding them manually, lol.

Elitezen
  • 6,551
  • 6
  • 15
  • 29

2 Answers2

2

You can use Array#map along with Array#join

This Is Assuming content Returns an Array

db.push('myItems', `Blue`, `Black`, `Red`)

const content = db.get('myItems')
const contentList = content.map((item, i) => `${i} ${item}`).join('\n')

channel.send(contentList)
// 0 Blue
// 1 Black
// 2 Red
Elitezen
  • 6,551
  • 6
  • 15
  • 29
0

I don't know the code but i suggest looping through the array and then doing something like: channel.send(numberLooped + content)

Tetie
  • 365
  • 1
  • 14