Solution Review: Create Phone Number
Explore how to format an array into a phone number string using JavaScript slice and join methods. Understand step-by-step how to extract array segments and combine them with template literals to build the final formatted string.
We'll cover the following...
We'll cover the following...
There are various ways to solve the problem in the previous lesson. However, the question required the use of slice to solve the problem. Let’s discuss the solution now.
Solution
Explanation
This is an obvious solution. To take out the values from specific indexes, we make use of the .slice method. To convert them to strings we use the .join method. We use template literals to form our final string.
...