For loop only gives the last value of an array

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[127][127]. What have I done wrong?

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

TypeScript for JavaScript Developers

TypeScript is an object-oriented programming language developed and maintained by the Microsoft Corporation. It is a superset of JavaScript and contains all of its elements. TypeScript is a compiled language. You write TypeScript and it compiles to JavaScript. Essentially, you’re writing JavaScript, but with a type system. JavaScript developers should have a seamless transition because the languages are the same

How to Clone an Array in JavaScript?

In this JavaScript tutorial, you'll learn how to clone an array in JavaScript. Because arrays in JS are reference values, so when you try to copy it using the = it will only copy the reference to the original array and not the value of the array.

What TypeScript taught me about JavaScript

What TypeScript taught me about JavaScript. TypeScript was designed to make the most sense out of any JavaScript code. How void behaves in both TypeScript and JavaScript. What Symbols are and why they can be unique. Why substitutability is such an important concept for TypeScript