How to get an object value out of the array so they are elements of another array

  arrays, javascript, object

Let’s say I have an array of objects. I want to create another array that only contains the key values of the objects that are inside of the previous array. Additionally, I don’t know how many elements the x array will contain, it’s depended on the user. Is there any way? I tried mapping, filtering, object.values(), but everything returns a new array of objects.

x = [{1: 182}, {2: 912}, {3: 51}, …]
y = [182, 912, 51, ...]

Source: Ask Javascript Questions

LEAVE A COMMENT