How to Create An Array From A String in Javascript

In this article, you will learn how to create an array from a string in Javascript. Let’s say you have a string variable named ‘a’…

The post How to Create An Array From A String in Javascript appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Ariessa Norramli

In this article, you will learn how to create an array from a string in Javascript.

Let’s say you have a string variable named ‘a’ with value “codesource”.

var a = "codesource";

In order to create an array from the string, you can use the Array.from() method. In this example, you will be creating an array of characters from the string variable ‘a’.

var a = "codesource";

console.log(Array.from(a));
// => ["c", "o", "d", "e", "s", "o", "u", "r", "c", "e"]

Note: The Array.from() method functions by creating an array from the supplied parameter.

The post How to Create An Array From A String in Javascript appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Ariessa Norramli


Print Share Comment Cite Upload Translate Updates
APA

Ariessa Norramli | Sciencx (2021-02-20T11:23:45+00:00) How to Create An Array From A String in Javascript. Retrieved from https://www.scien.cx/2021/02/20/how-to-create-an-array-from-a-string-in-javascript/

MLA
" » How to Create An Array From A String in Javascript." Ariessa Norramli | Sciencx - Saturday February 20, 2021, https://www.scien.cx/2021/02/20/how-to-create-an-array-from-a-string-in-javascript/
HARVARD
Ariessa Norramli | Sciencx Saturday February 20, 2021 » How to Create An Array From A String in Javascript., viewed ,<https://www.scien.cx/2021/02/20/how-to-create-an-array-from-a-string-in-javascript/>
VANCOUVER
Ariessa Norramli | Sciencx - » How to Create An Array From A String in Javascript. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/02/20/how-to-create-an-array-from-a-string-in-javascript/
CHICAGO
" » How to Create An Array From A String in Javascript." Ariessa Norramli | Sciencx - Accessed . https://www.scien.cx/2021/02/20/how-to-create-an-array-from-a-string-in-javascript/
IEEE
" » How to Create An Array From A String in Javascript." Ariessa Norramli | Sciencx [Online]. Available: https://www.scien.cx/2021/02/20/how-to-create-an-array-from-a-string-in-javascript/. [Accessed: ]
rf:citation
» How to Create An Array From A String in Javascript | Ariessa Norramli | Sciencx | https://www.scien.cx/2021/02/20/how-to-create-an-array-from-a-string-in-javascript/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.