how can i reverse 'fox' word? please solve this

var str = ‘The quick brown fox jumped over the lazy dog.’;

let words = str.split(’ ');
console.log(words[3]);

let name = words.foreach(function(str) {
    const word = str.split(’’);
    word.reverse();
    return word.join(’’);
})
console.log(name(words));

Hi @rahulmad8,

This post was moved to a different board that fits your topic of discussion a bit better. This means you’ll get better engagement on your post, and it keeps our Community organized so users can more easily find information.

As you’ll notice, your Topic is now in the Project Development Help board. No action is needed on your part; you can continue the conversation as normal here.

Let me know if you have any other questions or if I can help with anything else.

Cheers!

First you should create name as an empty array, and then correct the spelling in the foreach method to words.forEach. I have rewritten the code so that it works, and all the words are reversed but within their original position.

var str = ‘The quick brown fox jumped over the lazy dog.’;

let words = str.split(’ ‘);
console.log(words[3]);
let name = [];
words.forEach(function(str) {
let word = str.split(’’);
word.reverse();
name.push(word.join(’’));
})
console.log(name[3]);