In javascript how to add or remove 's' from a quantity string -


I have a string returned from the database such as 7 months 5 days .

The problem occurs when 1 month is 1 day, it is still showing in 1 month 1 day , in the letter s Code> month and day .

And I do not have permission to use such a bracket <1> 1 month 1 day (days) .

How can I make a condition that if it is less than 2 days then remove s ?

Do not work below What do I do?

JS

  var YYMM = '1 month 1 day'; // counterfeit data if (YYMM.indexOf ('1')> gt; -1) {YYMM.replace ('s', ''); Console.log ('YYMM:', YYMM); }  

Many thanks

replace it with single regexp do it

  var reg = / b1 \ b \ s (month | days) s / g; Warning ('1 month 1 day'. Location (reg, '1 $ 1')); Warning ('11 Months 21 Days'. Location (reg, '1 $ 1')); Alert ('12 months 1 day'. Location (reg, '1 $ 1'));  


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -