Answer the question
In order to leave comments, you need to log in
How to fix missing definitions of some standard js methods in typescript?
I am writing a custom pipe. At the input and output - a string (9-digit number is expected).
It is necessary to bring 123456789 to the form (12) 345-67-89.
I tried:
value.splice ( 0, 0, "(" );
value.splice ( 2, 0, ") " );
Answer the question
In order to leave comments, you need to log in
in the browser this method (on pure js) works properly
`(${value.slice(0, 2)}) ${value.slice(2, 5)}-${value.slice(5, 7)}-${value.slice(7)}`
There is no such method for strings. There is such a method for arrays. String !== Array. Break the string into an array of characters, twist them as you like, then put them back together.
let value = "123456789";
let numbers = value.split("");
numbers.splice ( 0, 0, "(" );
numbers.splice ( 3, 0, ")" );
numbers.join(""); // (12)3456789
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question