I have defined the following object:
let myObj = {
my: 'name',
is: 'Inigo Montoya',
prepare: 'to die!'
}
What is the best way of making myObj to equal { "my name is Inigo Montoya prepare to die!" }?
I know you can Stringify using JSON, but I'd like doing it in native Javascript. I've tried the following to get a string made of all the object properties + values:
let combined = Object.entries(obj).forEach(entire => {
return `${entrie[0]} ${entrie[1]}` });
but I only get undefined.
I'd love understanding why I'm getting undefined in this particular case, and also hearing what would you say the best way to solve the problem described above. Thanks!!
.forEachalways returnsundefined, you probably want.map()