Working with JavaScript Array of Strings

Today, we will explore the world of JavaScript arrays of strings.

When working with textual data, string arrays play an important role.

Keep reading! To learn how to work with string arrays, manipulate them effectively, and utilize them in your code correctly.

What is Array of String?

A string array is simply an array that contains multiple string values. An array is a variable that can hold multiple values of the same type.

String array specifically, stores string values, which are combinations of characters.

How to create and initialize arrays of strings?

To create an array of strings in JavaScript, you can use the array literal syntax or the Array constructor.

For example:

let sampleArray = ["it", "source", "code"];
console.log(sampleArray)

Output:

[ 'it', 'source', 'code' ] 

Or we can also use the new keyword to create an array of strings in JavaScript.

let sampleArray = new Array("hi", "welcome", "to", "it", "source", "code");
console.log(sampleArray)

Output:

[ 'hi', 'welcome', 'to', 'it', 'source', 'code' ]

How to access and modify elements in an array of strings?

You can access elements in an array of strings using bracket notation, where the index of the first element is 0.

For example:

let sampleArray = ["it", "source", "code"];
console.log(sampleArray[0]); // "it"
sampleArray[1] = "new value";
console.log(sampleArray); // ["it", "new value", "code"]

Output:

it
[ 'it', 'new value', 'code' ]

Here’s the additional example of accessing and modifying elements in an array of strings:

Adding elements

You can add elements to an array using methods like push (to add to the end) or unshift (to add to the beginning).

For example:

const sampleArray = ["it", "source", "code"];
sampleArray.push("offers free sourcecode");
console.log(sampleArray);

Output:

[ 'it', 'source', 'code', 'offers free sourcecode' ]

Removing elements

You can remove elements from an array using methods like pop (to remove from the end) or shift (to remove from the beginning).

Here’s an example of pop:

const sampleArray = ["it", "source", "code"];
sampleArray.pop();
console.log(sampleArray);

Output:

[ 'it', 'source' ]

Here’s an example of shift:

const sampleArray = ["it", "source", "code"];
sampleArray.shift();
console.log(sampleArray);

Output:

[ 'source', 'code' ]

How to use built-in array methods with arrays of strings?

JavaScript provides many built-in methods for working with arrays, including arrays of strings.

Here are some examples of how to use the built-in array methods with arrays of strings:

join() method

This method concatenates all elements in an array into a string. Here’s an example:

let str = ["it", "source", "code"];
let result = str.join(", ");
console.log(result); 

Output:

it, source, code

slice() method

This method returns a new array containing a portion of the original array.

Here’s an example:

let str = ["it", "source", "code"];
let result = str.slice(1, 3);
console.log(result); 

Output:

[ 'source', 'code' ]

indexOf() method

This method returns the first index at which a given element can be found in the array.

Here’s an example:

let str = ["it", "source", "code"];
let result =str.indexOf("code");
console.log(result); 

Output:

2

splice() method

This method changes the contents of an array by removing or replacing existing elements and/or adding new elements.

Here’s an example:


const sampleArray = ["it", "source", "code"];
sampleArray.splice(1, 1, "example");
console.log(sampleArray);

Output:

[ 'it', 'example', 'code' ]

map() method

This method creates a new array with the results of calling a provided function on every element in the calling array.

Here’s an example:

const sampleArray = ["it", "source", "code"];
const mapped = sampleArray.map(samarr => samarr.toUpperCase());
console.log(mapped);

In this example we use the toUpperCase() method.

Output

[ 'IT', 'SOURCE', 'CODE' ]

filter() method

This method creates a new array with all elements that pass the test implemented by the provided function.

Here’s an example:

const sampleArray = ["it", "source", "code"];
const filtered = sampleArray.filter(samarr => samarr.length > 4);
console.log(filtered);

Output:

[ 'source' ]

How to convert an array of strings to a string?

To convert an array of strings to a string in JavaScript, you can use the join() method, which concatenates all elements in an array into a string.

For example:

let sampleArray = ["it", "source", "code"];
console.log(sampleArray.join());

Output:

it,source,code

How to sort an array of strings in JavaScript? 

You can sort an array of strings in JavaScript using the sort() method.

The sort() method sorts the elements in ascending order by default, converting them to strings and comparing their sequences of UTF-16 code units values .

Here’s an example:

const sampleArray = ["source", "code", "it"];
sampleArray.sort();
console.log(sampleArray);

Output:

[ 'code', 'it', 'source' ]

How to convert an Array of Strings to numbers in JavaScript

You can convert an array of strings to numbers in JavaScript using the map() method.

Here’s an example:

const stringArray = ["1", "2", "3", "4", "5"];
const numberArray = stringArray.map(Number);
console.log(numberArray);

Output:

[ 1, 2, 3, 4, 5 ]

In this example, we use the map() method to create a new array with the results of calling the Number function on every element in the calling array. This converts each string element to a number.

Here’s another solution

You can use the parseInt() function to parse a string argument and return an integer.

You can loop through each element in the array of strings and use parseInt() to convert each element to a number.

let stringArray = ["1", "2", "3", "4", "5"];
let numberArray = [];
for (let i = 0; i < stringArray.length; i++) {
    numberArray.push(parseInt(stringArray[i]));
}
console.log(numberArray);

Output:

[ 1, 2, 3, 4, 5 ]

Conclusion

In conclusion, this article provides a comprehensive exploration of working with JavaScript arrays of strings.

This article explains the concept of string arrays and demonstrates how to create and initialize them using various methods, such as array literals and constructors.

The article also covers essential operations like accessing and modifying elements in a string array, including adding and removing elements.

Moreover, it explores how to use built-in array methods specifically tailored for arrays of strings, such as join(), slice(), indexOf(), splice(), map(), and filter().

We are hoping that this article provides you with enough information that helps you understand JavaScript array of strings.

You can also check out the following article:

Thank you for reading itsourcecoders 😊.

Frequently Asked Questions

Is JavaScript still worth learning in 2026?
Yes. JavaScript runs on 98% of websites for the front-end, dominates the back-end via Node.js, powers mobile apps through React Native, builds desktop tools through Electron, and is the scripting layer for most AI tooling (LangChain.js, OpenAI SDK, Vercel AI). Whether you target web, mobile, AI, or full-stack capstones, JavaScript is the broadest single language you can learn.
What is the difference between var, let, and const?
var is function-scoped, hoisted to the top of its scope, and can be redeclared, which leads to bugs in modern code. let is block-scoped (only visible inside the nearest {}) and can be reassigned. const is block-scoped and cannot be reassigned, although object contents can still mutate. Default to const for everything, switch to let only when you actually need to reassign, and avoid var in any code written after 2017.
Which JavaScript version should I target in 2026?
Target ES2020 (ES11) as the safe baseline because every modern browser and Node.js 14+ supports it fully. ES2022 adds useful features like top-level await, private class fields with the # prefix, and the .at() array method. If you are writing for older browsers (IE11 or older Android WebViews), transpile down with Babel or use a build tool like Vite, esbuild, or webpack.
What is the best free editor for JavaScript?
Visual Studio Code is the industry standard, free, with built-in IntelliSense, debugger, terminal, Git, and a huge extension marketplace (ESLint, Prettier, GitHub Copilot, Tailwind). Install the JavaScript and TypeScript Nightly extension for the latest language features. JetBrains WebStorm is more powerful and free for students with a verified .edu email. For quick scratchpad work, the Chrome DevTools Sources panel includes a workspace and breakpoint debugger.
How do I run JavaScript locally vs in the browser?
In the browser: open DevTools with F12 (or right-click then Inspect), go to the Console tab, type or paste your code, press Enter. For HTML pages, add a script tag pointing to your .js file. Locally with Node.js: download Node from nodejs.org (LTS version), then run node script.js in your terminal from the file folder. Use the same Node setup for backend capstones, API integrations, and scripts that do not need a browser.
What can I build with JavaScript for my BSIT capstone?
Common BSIT capstones in JavaScript: full-stack web apps using React or Vue on the front-end with Node.js and Express on the back-end (MongoDB or MySQL for the database), real-time chat or notification systems using Socket.io, single-page dashboards with Chart.js or D3.js, cross-platform mobile apps with React Native, AI-powered chatbots using OpenAI SDK and LangChain.js, and Chrome extensions for productivity tools. Add Tailwind CSS for the UI and Vercel or Netlify for free deployment.

Caren Bautista


Technical Writer at PIES IT Solution

Responsible for crafting clear, well-structured, and beginner-friendly content across the platform. Handles the writing, proofreading, and editorial review of tutorials, guides, and documentation to ensure every article is accurate, readable, and easy to follow.

Expertise: Technical Writing · Content Creation · Documentation · Editorial Writing · JavaScript · TypeScript · Python · Python Errors · HTTP Errors · MS Excel
 · View all posts by Caren Bautista →

Leave a Comment