Understanding the Array.from() method in JavaScript 

What is Array.from() method in JavaScript, and how do we use it?

It is a versatile tool for creating new arrays from array-like or iterable objects.

In this article, we will dive into the syntax, parameters, and return value of Array.from() and explore its many uses through practical examples.

From creating arrays from strings, Sets, and Maps, to using map functions and creating typed arrays. So let’s get started!

What is array.from() in JavaScript?

Array.from() is a method in JavaScript that allows you to create a new array from an array-like or iterable object.

It means that you can use Array.from() to create an array from objects such as a string, a Set, or a Map.

Syntax

Array.from(arrayLike[, mapFn[, thisArg]])

Parameters

📌 arrayLike

An array-like or iterable object to convert to an array.

📌 mapFn (optional)

A map function to call on each element of the array.

📌 thisArg (optional)

The value to use as this when executing the map function.

Return value

A new Array instance.

The Array.from() method creates a new, shallow-copied Array instance from an array-like or iterable object.

The optional mapFn parameter allows you to execute a map function on each element of the array being created.

The optional thisArg parameter specifies the value to use as this when executing the map function.

Browsers that supports Array.from() method

The following are the browsers that supports Array.from()method:

✅Chrome

✅ Edge

✅ Firefox

✅ Safari

✅Opera

Different ways on how to use Array.from() method in JavaScrip

Let’s consider a few instances of utilizing the Array.from() method.

Use Array.from() method to create an array from a string

You can use Array.from() to create an array from a string, where each character in the string becomes an element in the new array

Here’s an example that demonstrates how to use Array.from() to create an array from a string:

const sampleString = "itsourcecode";
const sampleArray = Array.from(sampleString);

console.log(sampleArray);

In this example, we are using Array.from() to create a new array from the string “itsourcecode.” Each character in the string becomes an element in the new array.

Output:

[
  'i', 't', 's', 'o',
  'u', 'r', 'c', 'e',
  'c', 'o', 'd', 'e'
]

Use a map function

You can use the optional mapFn parameter of Array.from() to apply a function to each element of the array being created. For example, if you want to create an array of numbers from 1 to 5, and square each number, you can do this with Array.from():

Here’s an example that demonstrates how to use Array.from() with a map function:

const sampleSet = new Set([10, 20, 30]);
const sampleArray = Array.from(sampleSet, x => x * 5);

console.log(sampleArray);

In this example, we are using Array.from() to create a new array from a Set. The Set contains the values 10, 20, and 30.

We’re also using the optional mapFn parameter to apply a function that multiplies each element by 3.

The resulting array contains the following output.

Output:

[ 50, 100, 150 ]

Use Array.from() method to create an array from a Map

You can use Array.from() to create an array from a Map. A Map is an object that holds key-value pairs.

If you have a Map with the keys “Math”, “English”, “Science”, and “Programming” and the values 1, 2, 3, and 4 respectively, you can use Array.from() to create an array of the keys or values:

const myMap = new Map([["Math", 1], ["English", 2], ["Science", 3], ["Programming", 4]]);
const keysArray = Array.from(myMap.keys());
const valuesArray = Array.from(myMap.values());

console.log(keysArray); // [ 'Math', 'English', 'Science', 'Programming' ]
console.log(valuesArray); // [ 1, 2, 3, 4 ]

Output:

[ 'Math', 'English', 'Science', 'Programming' ]
[ 1, 2, 3, 4 ]

Use Array.from() method to create an array from a Set

You can use Array.from() to create an array from a Set. A Set is an object that lets you store unique values of any type.

If you have a Set with the values “Programming”, “English”, and “Math”, you can use Array.from() to create an array with these values:

const sampleSet = new Set(["Programming", "English", "Math"]);
const sampleArray = Array.from(sampleSet);

console.log(sampleArray);

Output:

[ 'Programming', 'English', 'Math' ]

Use Array.from() method to create an array from arguments

You can use Array.from() to create an array from the arguments object within a function. The arguments object is an array-like object that contains the arguments passed to the function.

Here’s an example that demonstrates how to use Array.from() to create an array from the arguments object:

function myFunction() {
const myArray = Array.from(arguments);
console.log(myArray);
}

myFunction(10, 20, 30, 40, 50);

Output:

[ 10, 20, 30, 40, 50 ]

Conclusion

In conclusion, the article introduces the Array.from() method in JavaScript, which is a versatile tool for creating new arrays from array-like or iterable objects.

The method allows you to convert various types of data, such as strings, Sets, Maps, and even the arguments object, into arrays.

This article explains the syntax and parameters of Array.from(), including the optional map function for custom transformations.

Also, practical examples are provided for demonstrating how to use the method in different scenarios.

We are hoping that this article provides you with enough information that helps you understand the array.from in JavaScript. 

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