Home | Mailing List | Blog | Tutorial Videos

Copying Arrays

Which of the following methods are valid ways to copy mainArray ?

const mainArray = ['one', 'two', 'three', 'five', 'four'];

// A
const a = mainArray;

// B
const b = [ ...mainArray ];

// C
const c = [];
mainArray.forEach(item => {
  c.push(item);
});

Select one: