1

I have object like this

  Names = [ 
            {
                group: 'BII',
                categories: null
            },
            {
                group: 'GVL',
                categories: []
            }
   ];

I need to create new array of string that will look like this

Groups = ['BII','GVL'];

Is there some simple solution in Angular or i need to check all properties in object?

4 Answers 4

10

Try this:

let Groups = Names.map((a) => a.group)

Sign up to request clarification or add additional context in comments.

Comments

3

Try like this:

Working demo

if you do not want distinct, do this:

this.Names.map(x => x.group)

For distinct,

this.distinctresult = Array.from(new Set(this.allResult));

Comments

1

const names = [ {
            group: 'BII',
            categories: null
        },
        {
            group: 'GVL',
            categories: []
        }];

let result = names.map(({group}) => group);
console.log(result);
you can use map

Comments

0
let result = Names.map(({  name }) => name.group)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.