Thursday, December 6, 2018

Convert a string to an array of characters using ES6 spread syntax

This tutorial explains how to Convert a string to an array of characters using ES6 spread syntax. Lets see the below examples, where we are using split method and spread operator to convert string to an array of characters.
Convert a string to an array of characters using ES6 spread syntax


Method -1 : 

Lets see this example, where we are using split method to convert string to an array of characters.
var word = "skptricks Blog"

// using javascript split function.
var getData = word.split("");

console.log(getData)

Output:-
----------------------------------
> Array ["s", "k", "p", "t", "r", "i", "c", "k", "s", " ", "B", "l", "o", "g"]


Method -2 : 

Lets see this example, where we are using spread operator to convert string to an array of characters.
var word = "skptricks Blog"

// using javascript spread operator.
var getData = [...word];

console.log(getData)

Output:-
----------------------------------
> Array ["s", "k", "p", "t", "r", "i", "c", "k", "s", " ", "B", "l", "o", "g"]

This is all about Convert a string to an array of characters using ES6 spread syntax. Thank you for reading this article, and if you have any problem, have a another better useful solution about this article, please write message in the comment section.


No comments:

Post a Comment