In the given array of objects, I have the following data:
response: [0]
Data: '455'
[1]
Data: '456'
[2]
Data: '457'
var transformedArray = newlist.map(function (obj) {
return obj.Data;
});
By using the above function, I am able to convert the array of objects into a new array called 'transformedArray', which gives the output as follows:
transformedArray= ['455', '456', '457'];
If the array of objects instead contains multiple elements like below:
response: [0]
Data: '455'
Note: 'tre'
Id: '4'
[1]
Data: '456'
Note: 'bre'
Id: '5'
[2]
Data: '457'
Note: 'cre'
Id: '6'
I aim to achieve the following array output for the above set of objects:
transformedArray = ['455', 'tre', '4', '456', 'bre', '5', '457', 'cre', '6']
If you have any suggestions on what modifications should be made in the function below to obtain the desired 'transformedArray', please let me know:
var transformedArray = newlist.map(function (obj) {
return obj.Data;
});