I have an object which looks like this :
const data = {
students: [{
code: '1',
number: '22',
type: 'regular',
name: 'john',
age: '11',
class: 'A',
}, {
code: '2',
number: '23',
type: 'regular',
name: 'steve',
age: '12',
class: 'B',
}],
teachers: [{
code: '22',
number: '101',
type: 'intern',
name: 'mac',
}, {
code: '23',
number: '102',
type: 'perm',
name: 'jess',
}],
};
It has different keys and values.
Here, I am trying to massage this data so that I can obtain the following result: So I am trying to get an array which will have only students data and other which will have teachers data from one function itself.
const result1 = [{
code: '1',
number: '22',
type: 'regular',
name: 'john',
}, {
code: '2',
number: '23',
type: 'regular',
name: 'steve',
}];
const result2 = [{
code: '22',
number: '101',
type: 'intern',
name: 'mac',
}, {
code: '23',
number: '102',
type: 'perm',
name: 'jess',
}];
what I tried is :
const getData = ({data = []}) => {
data?.map({ code,
number,
regular,
name } ) => {
return{
code,
number,
regular,
name
}}
}
getData(data.students)
getData(data.teachers) // How do get this data in one function call itself
This gives me the result , but for this I need to call this function twice once for students and one for teachers. I want to call this function once.
Thanks