How to use JavaScript Array.from()

Array from

On this page

Array from() Method

Program to use JavaScript Array.from() method

let a = 'JavaScript';
    let b = Array.from(a);
    console.log(b);
    

Output

[
      'J', 'a', 'v', 'a',
      'S', 'c', 'r', 'i',
      'p', 't'
    ]
    

Steps Description

  • Declare two variable a and b
  • Initialize two variable a and b with value of string a = ‘JavaScript’ and b = Array.from(a)
  • Array.from() method creates new array from array element
  • The value of b variable is displayed with the help of console.log inbuilt function