DEV Community

ivkeMilioner
ivkeMilioner

Posted on • Edited on

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)