I have an array of objects (myObjsArr
). The object contains 2 methods:
obj: {
getUserId(), // returns a string. For instance, "123"
getSubUserIds(), // returns an array of strings. For instance, ["abc", "abc2", ...]
}
I'm looping this array of objects to create 2 arrays.
const userIds = [];
const subUserIds = [];
myObjsArr.forEach((obj) => {
userIds.push(obj.getUserId());
obj.getSubUserIds(element => {
subUserIds.push(element);
})
});
This works, but seems not efficient. How could I improve my code?
Thanks