Here is Your Complete Guide about JS Array : part -3

Here is Your Complete Guide about JS Array : part -3

in this part, we will see how to convert other datatype to arrays and vice versa

String to Array

const str = 'abcd';
console.log(str.split(''))    //output:- ['a','b','c','d']
console.log(Array.from('abcd')   //output:- ['a','b','c','d']

Array to string

const arr = ['a','b','c','d'];
console.log(arr.join('');    //output:- 'abcd'

Object to Array

use Object.entries()

set to Array

Array.from(mySet)

Array to set

const mySet = new Set([1,2,3,2,3]);

Read more about other part of this series:-

  1. krishnasaini.hashnode.dev/here-is-your-comp..
  2. krishnasaini.hashnode.dev/here-is-your-comp..
  3. krishnasaini.hashnode.dev/here-is-your-comp..
  4. krishnasaini.hashnode.dev/here-is-your-comp..