Below is the code snippet I am currently working on:
const json = `{"BTC":{"available":0.00024868,"onOrder":0,"btcValue":0.00024868,"btcTotal":0.00024868},"LTC":{"available":0,"onOrder":0,"btcValue":0,"btcTotal":0},"ETH":{"available":0,"onOrder":0,"btcValue":0,"btcTotal":0},"NEO":{"available":0,"onOrder":0,"btcValue":0,"btcTotal":0},"BNB":{"available":0.08943066,"onOrder":0,"btcValue":0.0004663808919,"btcTotal":0.000...
const data = JSON.parse(json);
var Table = require('cli-table');
const chalk = require("chalk"
// Processing the data
const processed = Object.entries(data)
.filter(([, { available }]) => available > 0)
.map(([asset, { available, btcValue }]) => {
return { asset, available, btcValue };
});
// Converting to array format
const asArray = processed.map(Object.values);
// Displaying the processed data in a tabular form
var table = new Table({
head: [chalk.green.bold('Coin'), chalk.green.bold('Available'), chalk.green.bold('BTC Value')]
, colWidths: [25, 25, 25]
});
// Pushing data into the table regardless of the array length
asArray.forEach(item => {
table.push(item);
});
// Converting the table for display
var tableDisplay = table.toString();
console.log(tableDisplay);
The goal is to automatically include each index of the 'asArray' into the table without manually changing the code every time.
With this updated approach, the code can adapt to the array's length dynamically.