Hi i want to convert by object into an array i don't have any ideas how to do that.
Object
{ stops: [ 'Route1', 'Route2' ], time: [ '12:00 am', '12:30 am', '01:00 am', '01:30 am', '02:00 am' ], _id: 5c636357bc92ec0e44a44946}
how to parse time: [ '12:00 am', '12:30 am', '01:00 am', '01:30 am', '02:00 am' ]
, like this one.
Array
[ '12:00 am', '12:30 am', '01:00 am', '01:30 am', '02:00 am' ]
Use . notation to access the time property
var obj={ stops: [ 'Route1', 'Route2' ], time: [ '12:00 am', '12:30 am', '01:00 am', '01:30 am', '02:00 am' ], _id: '5c636357bc92ec0e44a44946'} console.log(obj.time)
for converting all things into an array
let obj={ stops: [ 'Route1', 'Route2' ], time: [ '12:00 am', '12:30 am', '01:00 am', '01:30 am', '02:00 am' ], _id: 5c636357bc92ec0e44a44946}
let arr=[...obj.stops,...obj.time,obj._id]
and simply if you want to convert only time attribute then
let obj={ stops: [ 'Route1', 'Route2' ], time: [ '12:00 am', '12:30 am', '01:00 am', '01:30 am', '02:00 am' ], _id: 5c636357bc92ec0e44a44946}
let arr=[...obj.time]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.