Reputation: 23
var date = {
"1/2/20":500,
"2/2/20":601,
"3/2/20":702,
"4/2/20":803,
"5/2/20":904
}
How do I get only the number so it prints without the date like so:
500
601
702
803
904
Upvotes: 2
Views: 50
Reputation: 111
You can try the following code:
let date = {
"1/2/20":500,
"2/2/20":601,
"3/2/20":702,
"4/2/20":803,
"5/2/20":904
}
for (let key of Object.keys(date)) {
let val = date[key];
console.log(val)
}
Upvotes: 0
Reputation: 31761
You're looking for Object.values.
var date = {
"1/2/20":500,
"2/2/20":601,
"3/2/20":702,
"4/2/20":803,
"5/2/20":904
}
console.log(Object.values(date))
➜ ~ node foo.js
[ 500, 601, 702, 803, 904 ]
If you want to match output exactly add a call to join.
console.log(Object.values(date).join('\n'))
➜ ~ node foo.js
500
601
702
803
904
Upvotes: 5