javascript - Split a string in AngularJs 2 - Stack Overflow

I have an object profileObj.details[0].time which is equal to "10AM-4PM"I want to split this

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745674916a4639629.html

相关推荐

  • javascript - Split a string in AngularJs 2 - Stack Overflow

    I have an object profileObj.details[0].time which is equal to "10AM-4PM"I want to split this

    21天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信