Demo: Create an Array from a String

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.

this is my new tutorial

Code Used in This Demo Top ↑

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.




Subscribe to our YouTube Channel here



plus2net.com










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer