how to create an array from a string in javascript code example
Example 1: js array to string
var myArray = ['no','u'];
var myString = myArray.toString();
Example 2: string to array javascript
const str = 'Hello!';
console.log(Array.from(str)); // ["H", "e", "l", "l", "o", "!"]
Example 3: js string to array
var myString = 'no,u';
var MyArray = myString.split(',');//splits the text up in chunks
Example 4: array to string javascript
var cars = ["Volvo", "BMW", "Audi", "Chevrolet"];
console.log(cars.toString());
//Output: Volvo,BMW,Audi,Chevrolet
Example 5: array to string javascript
<array>.join(<splitting character(s)>);
Example 6: split() javascript
let countWords = function(sentence){
return sentence.split(' ').length;
}
console.log(countWords('Type any sentence here'));
//result will be '4'(for words in the sentence)