I have an array with string elements. I need to swap letters in words, leaving the word order in the array unchanged.
- It is necessary to replace the array, then rearrange the letters, write the code that does it - Roman C
|
1 answer
let array = ['какой-то', 'набор', 'слов']; for (let i = 0; i < array.length; i++) { array[i] = array[i].split('').reverse().join(''); } console.log(array); Or as suggested by yar85 using the map () method:
let array = ['какой-то', 'набор', 'слов']; array = array.map(s => [...s].reverse().join('')); console.log(array); - The code works, thanks. - Juzo
- oneThe short version is:
array = array.map(s => [...s].reverse().join(''));- yar85
|