Numeronym generation Problem statement
I need to generate numeronyms from a string, let's say qwerty as follows:
qwerty
q1erty
q2rty
q3ty
q4y

Code
Can this solution can be improved or if there's any better approach?


const str = 'qwerty';
const lastCharPos = str.length - 1;

str
  .split('')
  .map(
    (_, i) =&gt;
      i !== lastCharPos &amp;&amp;
      console.log(`${str[0]}${i ? i : ''}${str.slice(i + 1, lastCharPos)}${str[lastCharPos]}`)
  );
Know the language
Part of being a programmer is being familiar with the language/s you are using. These days languages are changing yearly thus keeping up to date is very important. MDN JavaScript provides a good JavaScript reference. Every now and then its good to peruse the site to keep your knowledge up to date.
Strings
String.slice will slice to the end of the string if you don't include the second argument. Thus there is no need for the variable lastCharPos
If the arguments for String.slice are negative the position of the slice if from the end of the string. eg &quot;abcd&quot;.slice(-2) will return &quot;cd&quot;
You can String.split a string using ... (Spread syntax) spread operator. eg[...str].map
Arrays
Array.map creates an array. You do not use the array and so you should have used Array.forEach
Often when using arrays and their iteration functions like map, it forces you to adapt the code to fit the array function's needs, increasing the complexity of the source and at runtime.  You do this twice...

The need to soak the first argument of map map((_, i) =&gt; which is a hack in my view.
As you have no control over the number of iterations you are forced to add two statements i !== lastCharPos and i ?  in the ternary expression i ? i : ''

Improving the code.
Always make your code portable by wrapping it in a function
Code should be focused on one task (role) at a time. Because you created the code inline (not a function) you have combined various tasks into one.

Creating the set of strings
Outputting to the console.

As a function you can separate the output from the creation, returning an array of strings that you can then use as needed. eg Output to console.
The Array iteration functions are too cumbersome for what your code does. You can use a while loop and push the built string to an array which you return at the end.
Rewrite
Your function does not output anything if the string length is &lt;= 1. It is unclear if this is just an output requirement. The rewrite will return the input string (as first item in the array) no matter what its size
The string is sliced using a negative index to slice from the end of the string.
I used a while loop but you can also use a for loop
Using while loop
function numeronyms(str) {
    const result = [str], len = str.length;
    var i = 1;
    while (i &lt; len - 1) { result.push(str[0] + (i++) + str.slice(i - len)) }
    return result;
}

Using for loop
function numeronyms(str) {
    const result = [str], len = str.length;
    for (let i = 2; i &lt; len; i ++) {
        result.push(str[0] + (i - 1) + str.slice(i - len));
    }
    return result;
} 

Usage
To use the function so that it behaves the same as your code it needs to check the string length.
const str = &quot;qwerty&quot;;
if (str.length &gt; 1) { console.log(numeronyms(str)) }

or
const str = &quot;qwerty&quot;;
str.length &gt; 1 &amp;&amp; console.log(numeronyms(str));

Or just assign the array for use later
const numers = numeronyms(&quot;qwerty&quot;);