I have an object profileObj.details[0].time which is equal to "10AM-4PM" I want to split this string into 10AM and 4PM .
please help to solve this issue. Thanks in advance
I have an object profileObj.details[0].time which is equal to "10AM-4PM" I want to split this string into 10AM and 4PM .
please help to solve this issue. Thanks in advance
Share Improve this question edited Nov 29, 2016 at 7:27 Ritesh Bhat asked Nov 29, 2016 at 7:26 Ritesh BhatRitesh Bhat 9761 gold badge20 silver badges32 bronze badges 1-
1
So use the string function
.split('-')
– Jes Commented Nov 29, 2016 at 7:26
1 Answer
Reset to default 5You can use .split
together with array destructuring
:
const [first, second] = "10AM-4PM".split('-');
console.log(first); // 10am
console.log(second); // 4pm