i have an array named "all_items" and i want to split that to two arrays named "self" and "others".
I want to loop through each item in "all_items" array and if that item is added by current_user then push it to "self" array if not "others" array
item = {
id: 0,
owner_id: 1,
name: "name",
}
Below is the algorithm,
group = () => {
const self = [];
const others = [];
for each item
if item is uploaded by current_user
self.push(item)
else
others.push(item)
return {self, others}
}
How can i implement the above in react or javascript. Could someone help me with this. thanks.
current_userid to id in the Object, if true add to self else add toothers