M
M
Mikhail Peyzov2020-08-03 15:43:47
Node.js
Mikhail Peyzov, 2020-08-03 15:43:47

How to replace part of the text so that the other part remains unchanged?

I have this code in node.js:

const prettyMilliseconds = require("pretty-ms");
prettyMilliseconds(process.uptime, { keepDecimalsOnWholeSeconds: false });

and I need it so that the letter "h" is replaced by the string: `hours`, the string "m" by `minutes`, etc. How can I do that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Developer, 2020-08-03
@Payz

var str = 'h m';
str = str.replace('h', 'часов').replace('m', 'минут');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question