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
.split('-')
– Jes
Commented
Nov 29, 2016 at 7:26
You can use .split
together with array destructuring
:
const [first, second] = "10AM-4PM".split('-');
console.log(first); // 10am
console.log(second); // 4pm