select column values from array typescript 1

select column values from array typescript

var result1 = [
    {id:1, name:'Sandra', type:'user', username:'sandra'},
    {id:2, name:'John', type:'admin', username:'johnny2'},
    {id:3, name:'Peter', type:'user', username:'pete'},
    {id:4, name:'Bobby', type:'user', username:'be_bob'}];
    
 
var data = result1.map(t=>t.name);
console.log(data);

Here is what the above code is Doing:
1. We have an array of objects.
2. We use the map() method to iterate through each object in the array.
3. We return the name property of each object.
4. The map() method returns a new array with the names.

Similar Posts