0

I have an array as,

const headArray = ['id', 'correlationId', 'category', 'subCategory'];

I want to convert this as below,

    const columns =  [{ field: 'id', headerName: 'id'},
                      { field: 'correlationId', headerName: 'correlationId'},
                      { field: 'category', headerName: 'category'}
                      { field: 'subcategory', headerName: 'subcategory'}];

I tried many ways but I couldn't do this. If anyone know the method please tell me.

1
  • This is not JSON. Please read the usage description of the json tag. Commented Mar 10, 2022 at 14:26

1 Answer 1

2

I guess you can use map to achieve this :

const columns = headArray.map(value => ({field: value, headerName: value}));

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.