Shilpa
Published in : 2022-03-06
I have an object as given below,
{"parking_space" : "16 X 25 FEET","parking_location" : "Address line items""parking_country" : "CA""parking_book_start_date": "03/06/2022 10:00:00","parking_book_start_date": "03/06/2022 20:30:00"}
I am using one Chart library, which is expecting an array format to be passed as DATA.
How do I convert these object keys to an array to pass as data in chart library?
Join our community and get the chance to solve your code issues & share your opinion with us
Sign up Now
Rakshit Date : 2022-03-06
Best answers
34
Best answers
34
There are two solutions to achieve your requirements.
#Solution 1 [Recommended]: Use Object.entries() - to convert object to array directly with one-liner question.
See live demo here
#Solution 2: Use Object.keys() - to get an array of all keys inside your object, iterate throughout all keys and get values. You need one array to manage keys and values according to your requirements. If your keys contains null values, you need a null check. inshort, this another solution is bit lengthy so I recommend to go with first solution,
Hope it will work for you.