Below is an array containing objects:
objectArray = [{name: “E-mail”, data_type: “text”}, {name: “Number”, data_type: “text”}, {name: “Person”, data_type: “text”}]
The goal is to extract only the name
property from each object and use it as a key in a new object as shown below:
counterObject = {E-mail: 0, Number: 0, Person: 0}
An attempt was made to achieve this using the map
method like so:
objectArray.map((elem) => {
return {[elem.name]:0};
})
However, the result obtained was:
[{Text: 0}, {Number: 0}, {E-mail: 0}, {Person: 0}, {Upload: 0}, {Date: 0}, {Link: 0}]