Getting keys of associative array in JavaScript

Ked*_*rni 1 javascript

I have heard that JavaScript does not support associative arrays. Is it true
I mean:

assocArray = [
  {a: ""},
  {b: ""},
  {c: ""}
];
Run Code Online (Sandbox Code Playgroud)

how to get the keys of above assocArray?

I tried using:

for (each in assocArray) {}
Run Code Online (Sandbox Code Playgroud)

it gives: 0, 1, 2

Mam*_*mun 5

You can try with flatMap()

The flatMap() method first maps each element using a mapping function, then flattens the result into a new array. It is identical to a map() followed by a flat() of depth 1, but flatMap() is often quite useful, as merging both into one method is slightly more efficient.

and Object.keys()

The Object.keys() method returns an array of a given object's own enumerable property names, in the same order as we get with a normal loop.

var assocArray = [{a : "" },{b : ""},{c : ""}]; 
var keys = assocArray.flatMap(i => Object.keys(i));
console.log(keys);
Run Code Online (Sandbox Code Playgroud)