How to array push key value with JavaScript?

To array push key value with JavaScript, we call the push method.

For instance, we write

const arr = ["left", "top"];
const x = [];

for (const a of arr) {
  x.push({
    [a]: 0,
  });
}

to loop through the arr array with a for-of loop.

Then we call x.push with an object with key a and value 0.

a is the value being looped through in arr.