-1

Is there a way to convert each word of a string to each have an array? For example, say I have the variable below.

Let str = "Just typing out some words"; I would like to convert this to what I have below

Let arrs = [[Just], [typing], [out], [some], [words]]

Is there any way that I can achieve this?

Aj4short
  • 11
  • 1
  • 2
  • Welcome to Stack Overflow! Please take the [tour] (you get a badge!) and read through the [help], in particular [*How do I ask a good question?*](/help/how-to-ask) Your best bet here is to do your research, [search](/help/searching) for related topics on SO, and give it a go. ***If*** you get stuck and can't get unstuck after doing more research and searching, post a [mcve] of your attempt and say specifically where you're stuck. People will be glad to help. *(not my downvote)* – T.J. Crowder Jul 02 '21 at 07:49
  • Yes it is possible. Share what you tried for better response. – Tushar Shahi Jul 02 '21 at 07:49
  • There certainly ways to achieve this, but kindly, show us what you have done so far to solve your issue. – FerdousTheWebCoder Jul 02 '21 at 07:50
  • [JavaScript break sentence by words](https://stackoverflow.com/questions/18473326/javascript-break-sentence-by-words) + `.map()` – Andreas Jul 02 '21 at 07:52

2 Answers2

0

const str = "Just typing out some words";
const arr = str.split(' ').map((node) => [node]);
console.log(arr);
Nitheesh
  • 19,238
  • 3
  • 22
  • 49
0

This would do the job.

str.split(" ").map((s) => [s])
Syam Pradeep
  • 59
  • 3
  • 11