I have an array with objects that looks like this:
0:
depth:0
id:37
index:0
label:"user"
name:"r"
next:(3) [265, 355, 387]
I want to match an id with the values inside next: Array(3)
findNext = function(idToMatch) {
const nodes = this.state.nodes;
for (let i = 0; i < nodes.length; i++){
if (nodes.next[i] === idToMatch) { return nodes[i].id }
}
};
idToMatch is one integer, just like id:37 in above example.
const nodes = this.state.nodes; is the array that contains objects as the one above.
How can I check if this.state.nodes[i].next contains the idToMatch and, if so, return this.state.nodes[i].id?
nodes? JSON format, perhaps?