I need to map an array coming from a server to change its fields into fields that are understandable by another server, so I can upload it into the second server.
My first challenge is to get the field names of the first array coming from the first server, display them to the user, to edit them and then using array.map()
I will create a new array with the user defined field names.
My first step is to get the array main field names. Lets say I have the following:
array = [{'name': 'John', 'lastname' :'Doe'},{'name': 'Roe', 'lastname' :'Doe'}]
The result would be like:
arrayFields = [{name, lastname}]
I tried to use getOwnPropertyNames()
:
getProp(){
console.log(Object.getOwnPropertyNames(this.array))
}
The result was like:
["0", "1", "length"]
0: "0"
1: "1"
2: "length"
I then tried with Object.assign()
as mentioned in this stack question:
getObject(){
let newObject = (Object.assign(this.array))
console.log(Object.getOwnPropertyNames(newObject))
}
But it was the same as previous result.
Here is the stackblitz I am working with.
The wanted result is like: ["name", "lastname"]