DEV Community

ivkeMilioner
ivkeMilioner

Posted on • Edited on

1 3

How to show phrases from textarea in paragraph?

How to show phrases from textarea in paragraph?

function chunkIt(str, chunk) {
var words = str.split(" ");
var arr = [];
for (var i = (chunk - 1); i < words.length; i++) {
var start = i - (chunk - 1);
arr.push(words.slice(start, start + chunk));
}
return arr.map(v => v.join(" "));
}

    const newTextArea = text => {
        const newEl = document.createElement('textarea');
        newEl.innerText = text;
        document.body.append(newEl);
    }


 var test = document.getElementById("textarea");
    console.log(chunkIt(test, 2));
    console.log(chunkIt(test, 3));
    console.log(chunkIt(test, 4));

    newTextArea(chunkIt(test, 4));
Enter fullscreen mode Exit fullscreen mode

https://codepen.io/drago-ivan/pen/yLybXqN

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More