I have an array of objects and some of those objects has groups which is an array,
i want all those objects from all groups and put it into one array of object, any idea how this could be done ?
what i want to have is this : GroupData= [ { id: "679d8044", name: "group 3" }, { id: "b9342eb8", name: "group 1" } ];
any idea ? english is not my mother language so could be mistakes.
you can try it here: https://codesandbox.io/s/react-list-array-of-objects-forked-rk34fj?file=/src/index.js
my code:
import React from "react";
import { render } from "react-dom";
const mydata = [
{
name: "living room",
groups: ""
},
{
groups: [
{
id: "679d8044",
name: "group 3"
}
],
name: "Area 1"
},
{
groups: [
{
id: "b9342eb8",
name: "group 1"
}
],
name: "Area 2"
}
];
const GroupData = mydata.find((grup) => grup.groups);
console.log(GroupData);
const App = () => <div></div>;
render(<App />, document.getElementById("root"));