最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Split a string in AngularJs 2 - Stack Overflow

programmeradmin2浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 5

You can use .split together with array destructuring:

const [first, second] = "10AM-4PM".split('-');
console.log(first); // 10am
console.log(second); // 4pm
发布评论

评论列表(0)

  1. 暂无评论