2
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
1

2 Answers 2

5

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
Sign up to request clarification or add additional context in comments.

Comments

0

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) 
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.