This demo starts with a sentence and creates an array by splitting the string at spaces. Press the button to see one array element per line.
const text = "this is my new tutorial";
const values = text.split(/\s+/);
console.log(values);
The page version uses textContent and DOM elements instead of inserting user-entered text with innerHTML. This avoids treating the input as HTML.
<label for="sourceText">Source text</label>
<input id="sourceText" type="text" value="this is my new tutorial">
<button id="createArrayBtn" type="button">Create Array</button>
<div id="arrayOutput" aria-live="polite"></div>
For the full explanation, see creating arrays and splitting strings into arrays.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.