1

Following is my input data

{ menu_name: 'testmenu',
 table_name: 'test_tbl',
 field_name: [ 'booktitle', 'bookid', 'bookauthor' ],
 field_type: [ 'varchar', 'int', 'varchar' ],
 field_size: [ '55', '11', '100' ] }

How can i convert this data to following array format

['testmenu','test_tbl','booktitle','varchar','55']
['testmenu','test_tbl', 'bookid','int','11']
['testmenu','test_tbl','bookauthor','varchar','100']
0

1 Answer 1

3

You can achieve this with the help of Array map method,

let obj = {
    menu_name: 'testmenu',
    table_name: 'test_tbl',
    field_name: ['booktitle', 'bookid', 'bookauthor'],
    field_type: ['varchar', 'int', 'varchar'],
    field_size: ['55', '11', '100']
}

let result = obj.field_name.map((x, i) => [obj.menu_name, obj.table_name, x, obj.field_type[i], obj.field_size[i]]);
console.log(result);

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

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.