ruttydm ruttydm - 3 months ago 13
Node.js Question

foreach loop for js object

I'm trying to make a foreach loop in javascript (nodejs) for the data i got from an api.

I already tried some examples from the internet without any results.

So i hope you can get me started.

When i use console.log(currenciesObj); for the object i get:



{ '1CR':
{ id: 1,
name: '1CRedit',
txFee: '0.01000000',
minConf: 3,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
ABY:
{ id: 2,
name: 'ArtByte',
txFee: '0.01000000',
minConf: 8,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
AC:
{ id: 3,
name: 'AsiaCoin',
txFee: '0.01000000',
minConf: 15,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
ACH:
{ id: 4,
name: 'Altcoin Herald',
txFee: '0.00000000',
minConf: 5,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
ADN:
{ id: 5,
name: 'Aiden',
txFee: '0.01000000',
minConf: 24,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
AEON:
{ id: 6,
name: 'AEON Coin',
txFee: '0.01000000',
minConf: 10,
depositAddress: 'WmrzAb4yy6i4otzaTZznsmaeBn8UKoBqS14XdW2DDzXr3DQnwz4o1XPJAJuo7QTqSoD9WVrdEQfn15udzhsJWmNR1jAEETQ2N',
disabled: 0,
delisted: 1,
frozen: 0 },
AERO:
{ id: 7,
name: 'Aerocoin',
txFee: '0.01000000',
minConf: 9,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
AIR:
{ id: 8,
name: 'AIRcoin',
txFee: '0.01000000',
minConf: 6,
depositAddress: null,
disabled: 1,
delisted: 1,
frozen: 0 },
AMP:
{ id: 275,
name: 'Synereo AMP',
txFee: '2.00000000',
minConf: 1,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
APH:
{ id: 9,
name: 'AphroditeCoin',
txFee: '0.01000000',
minConf: 3,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
ARCH:
{ id: 258,
name: 'ARCHcoin',
txFee: '0.01000000',
minConf: 18,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
AUR:
{ id: 10,
name: 'Auroracoin',
txFee: '0.01000000',
minConf: 15,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
AXIS:
{ id: 11,
name: 'Axis',
txFee: '0.01000000',
minConf: 15,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
BALLS:
{ id: 12,
name: 'Snowballs',
txFee: '6.40000000',
minConf: 20,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
BANK:
{ id: 13,
name: 'BankCoin',
txFee: '0.01000000',
minConf: 19,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
BBL:
{ id: 14,
name: 'BitBlock',
txFee: '0.01000000',
minConf: 6,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
BBR:
{ id: 15,
name: 'Boolberry',
txFee: '0.00500000',
minConf: 10,
depositAddress: '1D9hJ1nEjwuhxZMk6fupoTjKLtS2KzkfCQ7kF25k5B6Sc4UJjt9FrvDNYomVd4ZVHv36FskVRJGZa1JZAnZ35GiuAHf7gBy',
disabled: 0,
delisted: 0,
frozen: 0 },
BCC:
{ id: 16,
name: 'BTCtalkcoin',
txFee: '0.01000000',
minConf: 15,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
BCN:
{ id: 17,
name: 'Bytecoin',
txFee: '0.05000000',
minConf: 18,
depositAddress: '25cZNQYVAi3issDCoa6fWA2Aogd4FgPhYdpX3p8KLfhKC6sN8s6Q9WpcW4778TPwcUS5jEM25JrQvjD3XjsvXuNHSWhYUsu',
disabled: 0,
delisted: 0,
frozen: 0 },
BCY:
{ id: 269,
name: 'BitCrystals',
txFee: '4.00000000',
minConf: 2,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
BDC:
{ id: 18,
name: 'Black Dragon Coin',
txFee: '0.01000000',
minConf: 9,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
BDG:
{ id: 19,
name: 'Badgercoin',
txFee: '0.01000000',
minConf: 15,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
BELA:
{ id: 20,
name: 'BellaCoin',
txFee: '0.01000000',
minConf: 30,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
BITCNY:
{ id: 273,
name: 'BitCNY',
txFee: '1.00000000',
minConf: 50,
depositAddress: 'poloniexwallet',
disabled: 0,
delisted: 0,
frozen: 0 },
BITS:
{ id: 21,
name: 'Bitstar',
txFee: '0.01000000',
minConf: 15,
depositAddress: null,
disabled: 1,
delisted: 0,
frozen: 0 },
BITUSD:
{ id: 272,
name: 'BitUSD',
txFee: '0.15000000',
minConf: 50,
depositAddress: 'poloniexwallet',
disabled: 0,
delisted: 0,
frozen: 0 },
BLK:
{ id: 22,
name: 'BlackCoin',
txFee: '0.01000000',
minConf: 12,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
BLOCK:
{ id: 23,
name: 'Blocknet',
txFee: '0.01000000',
minConf: 24,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
BLU:
{ id: 24,
name: 'BlueCoin',
txFee: '0.01000000',
minConf: 120,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
BNS:
{ id: 25,
name: 'BonusCoin',
txFee: '0.01000000',
minConf: 9,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
BONES:
{ id: 26,
name: 'Bones',
txFee: '0.01000000',
minConf: 15,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
BOST:
{ id: 27,
name: 'BoostCoin',
txFee: '0.01000000',
minConf: 2000,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
BTC:
{ id: 28,
name: 'Bitcoin',
txFee: '0.00010000',
minConf: 1,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
BTCD:
{ id: 29,
name: 'BitcoinDark',
txFee: '0.01000000',
minConf: 20,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
BTCS:
{ id: 30,
name: 'Bitcoin-sCrypt',
txFee: '0.01000000',
minConf: 6,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
BTM:
{ id: 31,
name: 'Bitmark',
txFee: '0.01000000',
minConf: 6,
depositAddress: null,
disabled: 1,
delisted: 0,
frozen: 0 },
BTS:
{ id: 32,
name: 'BitShares',
txFee: '5.00000000',
minConf: 50,
depositAddress: 'poloniexwallet',
disabled: 0,
delisted: 0,
frozen: 0 },
BURN:
{ id: 33,
name: 'BurnerCoin',
txFee: '0.01000000',
minConf: 12,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
BURST:
{ id: 34,
name: 'Burst',
txFee: '1.00000000',
minConf: 20,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
C2:
{ id: 35,
name: 'Coin2.0',
txFee: '0.01000000',
minConf: 24,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
CACH:
{ id: 36,
name: 'CACHeCoin',
txFee: '0.01000000',
minConf: 3,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
CAI:
{ id: 37,
name: 'CaiShen',
txFee: '0.01000000',
minConf: 9,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
CC:
{ id: 38,
name: 'Colbert Coin',
txFee: '0.01000000',
minConf: 15,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
CCN:
{ id: 39,
name: 'Cannacoin',
txFee: '0.01000000',
minConf: 18,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
CGA:
{ id: 40,
name: 'Cryptographic Anomaly',
txFee: '0.00100000',
minConf: 12,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
CHA:
{ id: 41,
name: 'Chancecoin',
txFee: '0.01000000',
minConf: 2,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
CINNI:
{ id: 42,
name: 'CinniCoin',
txFee: '0.01000000',
minConf: 30,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
CLAM:
{ id: 43,
name: 'CLAMS',
txFee: '0.00100000',
minConf: 6,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
CNL:
{ id: 44,
name: 'ConcealCoin',
txFee: '0.01000000',
minConf: 20,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
CNMT:
{ id: 45,
name: 'Coinomat1',
txFee: '0.00000000',
minConf: 3,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
CNOTE:
{ id: 46,
name: 'C-Note',
txFee: '0.01000000',
minConf: 12,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
COMM:
{ id: 47,
name: 'CommunityCoin',
txFee: '0.01000000',
minConf: 15,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
CON:
{ id: 48,
name: 'Coino',
txFee: '0.10000000',
minConf: 12,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
CORG:
{ id: 49,
name: 'CorgiCoin',
txFee: '0.01000000',
minConf: 9,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
CRYPT:
{ id: 50,
name: 'CryptCoin',
txFee: '0.01000000',
minConf: 15,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
CURE:
{ id: 51,
name: 'Curecoin',
txFee: '0.01000000',
minConf: 5,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
CYC:
{ id: 52,
name: 'Conspiracy Coin',
txFee: '0.01000000',
minConf: 30,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
DAO:
{ id: 279,
name: 'The DAO',
txFee: '0.01000000',
minConf: 36,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
DASH:
{ id: 60,
name: 'Dash',
txFee: '0.05000000',
minConf: 12,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
DCR:
{ id: 277,
name: 'Decred',
txFee: '0.02000000',
minConf: 4,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
DGB:
{ id: 53,
name: 'DigiByte',
txFee: '0.01000000',
minConf: 15,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
DICE:
{ id: 54,
name: 'NeoDICE',
txFee: '0.00000000',
minConf: 5,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
GML:
{ id: 94,
name: 'GameleagueCoin',
txFee: '0.01000000',
minConf: 50,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 1 },
GNS:
{ id: 95,
name: 'GenesisCoin',
txFee: '0.01000000',
minConf: 12,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
GOLD:
{ id: 96,
name: 'GoldEagles',
txFee: '0.01000000',
minConf: 2,
depositAddress: null,
disabled: 1,
delisted: 1,
frozen: 0 },
GPC:
{ id: 97,
name: 'GROUPCoin',
txFee: '0.01000000',
minConf: 12,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
IOC:
{ id: 263,
name: 'IO Digital Currency',
txFee: '0.01000000',
minConf: 18,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
ITC:
{ id: 110,
name: 'Information Coin',
txFee: '0.01000000',
minConf: 15,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
IXC:
{ id: 111,
name: 'iXcoin',
txFee: '0.01000000',
minConf: 3,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
JLH:
{ id: 112,
name: 'jl777hodl',
txFee: '0.00000000',
minConf: 3,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
JPC:
{ id: 113,
name: 'JackpotCoin',
txFee: '0.01000000',
minConf: 15,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
JUG:
{ id: 114,
name: 'JuggaloCoin',
txFee: '0.01000000',
minConf: 15,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
KDC:
{ id: 115,
name: 'KlondikeCoin',
txFee: '0.01000000',
minConf: 8,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
KEY:
{ id: 116,
name: 'KeyCoin',
txFee: '0.01000000',
minConf: 15,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
LBC:
{ id: 280,
name: 'LBRY Credits',
txFee: '0.01000000',
minConf: 11,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
LC:
{ id: 117,
name: 'Limecoin',
txFee: '0.01000000',
minConf: 500,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
LCL:
{ id: 118,
name: 'Limecoin Lite',
txFee: '0.01000000',
minConf: 20,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
LEAF:
{ id: 119,
name: 'Leafcoin',
txFee: '0.10000000',
minConf: 7,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
LGC:
{ id: 120,
name: 'Logicoin',
txFee: '0.01000000',
minConf: 15,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
LOL:
{ id: 121,
name: 'LeagueCoin',
txFee: '0.01000000',
minConf: 15,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
LOVE:
{ id: 122,
name: 'LOVEcoin',
txFee: '0.01000000',
minConf: 8,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
LQD:
{ id: 123,
name: 'LIQUID',
txFee: '0.00000000',
minConf: 5,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
LSK:
{ id: 278,
name: 'Lisk',
txFee: '0.10000000',
minConf: 303,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
LTBC:
{ id: 124,
name: 'LTBCoin',
txFee: '1500.00000000',
minConf: 2,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
LTC:
{ id: 125,
name: 'Litecoin',
txFee: '0.00100000',
minConf: 4,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
LTCX:
{ id: 126,
name: 'LiteCoinX',
txFee: '0.01000000',
minConf: 20,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
MAID:
{ id: 127,
name: 'MaidSafeCoin',
txFee: '2.00000000',
minConf: 1,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
MAST:
{ id: 128,
name: 'MastiffCoin',
txFee: '0.01000000',
minConf: 20,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
MAX:
{ id: 129,
name: 'MaxCoin',
txFee: '0.01000000',
minConf: 9,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
MCN:
{ id: 130,
name: 'Moneta Verde',
txFee: '1.00000000',
minConf: 14,
depositAddress: 'VdttvavdPJNGD4NzPQf8Hn4tWUGyy9mQ58ScwXxKbx9ve4Kp8xXZ1kD1KmXUMp5qtX8GmRgMk16aNVBhENEHNQAb3488Ha7Vv',
disabled: 1,
delisted: 0,
frozen: 0 },
MEC:
{ id: 131,
name: 'Megacoin',
txFee: '0.01000000',
minConf: 6,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
METH:
{ id: 132,
name: 'CryptoMETH',
txFee: '0.01000000',
minConf: 7,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
MIL:
{ id: 133,
name: 'Millennium Coin',
txFee: '0.01000000',
minConf: 30,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
MIN:
{ id: 134,
name: 'Minerals',
txFee: '0.01000000',
minConf: 50,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 },
MINT:
{ id: 135,
name: 'Mintcoin',
txFee: '0.10000000',
minConf: 14,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
MMC:
{ id: 136,
name: 'MemoryCoin',
txFee: '0.01000000',
minConf: 5,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
MMNXT:
{ id: 137,
name: 'MMNXT',
txFee: '0.00000000',
minConf: 5,
depositAddress: null,
disabled: 0,
delisted: 0,
frozen: 0 },
YIN:
{ id: 252,
name: 'Yincoin',
txFee: '0.01000000',
minConf: 9,
depositAddress: null,
disabled: 0,
delisted: 1,
frozen: 0 } }





So i want to make an operation that needs to be done for each currency listed above.

(sorry for my english)

Answer

This will give you access to each element at the data's first level. It is good practice to use hasOwnProperty to protect from empty, undefined values, etc.

for (var key in currenciesObj) {
  if (currenciesObj.hasOwnProperty(key)) {
    console.log(currenciesObj[key]);
    //operation.
  }
}
Comments