# For loop only gives the last value of an array I've been trying to transpose a matrix (-like 2D array) in ES6 but the for loop only gives the last value of the original array and I have no idea what I did wrong.

I've been trying to transpose a matrix (-like 2D array) in ES6 but the for loop only gives the last value of the original array and I have no idea what I did wrong.

Suppose the size of the spectrum array is 128 x 128:

```const width = 128;
const height = 128;

var spectrum: Complex[][] = fft(data);
// Transpose spectrum array
var transposedData: Complex[][] = new Array(height).fill(new Array(width));
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
const c = spectrum[x][y].deepCopy();
transposedData[y][x] = c;
}
}
spectrum = transposedData;
console.log(spectrum);
```

This gives me a 2D array, every element of which is the value of spectrum. What have I done wrong?

## Learn Arrays And Array Methods in JavaScript

In JavaScript, an array is a data structure that contains list of elements which store multiple values in a single variable. The strength of JavaScript arrays lies in the array methods. Array methods are functions built-in to JavaScript that we can apply to our arrays — Each method has a unique function that performs a change or calculation to our array and saves us from writing common functions from scratch. In this video we are going to learn arrays and array methods like sort(), reverse(), join(), split(), pop(), push(), shift(), unshift(), toString(), delete array, etc.......

## Javascript Clear Array: How to Empty Array in Javascript

To clear array in Javascript, Substituting an existing array with a new array.Setting an array length prop to 0.Splice the whole array.

## Convert String To Array Using Javascript Split Method

In this tutorial, you’ll be going to learn how to convert string to array using javascript split method. The easiest approach to use javascript built-in method String.split(). JavaScript split string method return array of a substring after splitting a string based on the separator you provide. The separator might be a string, special character or […]

## How To Loop Through An Array In JavaScript

In this tutorial, you'll be going to learn how to loop through an array in javascript. The easiest way to use for loop and forEach array method.

## JavaScript Array Some Example | Array.prototype.some()

JavaScript array some() is the inbuilt method that tests whether at least one item in the array passes the test implemented by a provided function. The some() method is the JavaScript extension to the ECMA-262 standard; as such, it may not be present in other implementations of the standard. JavaScript array some() is the inbuilt method that tests whether at least one item in the array passes the test implemented by a provided function. It returns the Boolean value.