Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have an array of objects like this [Object, Object, Object]

the structure of every object like this

0: Object
   children: Array[0]
   node_id: 0
   parent_id: -2
   text: "(r , e , w)"
   value: 6

1: Object
   children: Array[0]
   node_id: 1
   parent_id: 0
   text: "(r)"
   value: 3

2: Object
   children: Array[0]
   node_id: 2
   parent_id: 0
   text: "(e , w)"
   value: 3

first I have for loop and I want to get parent_id every iteration

second I want to put last two objects into the children array inside first object Any help appreciated.

share|improve this question
    
Can you please be more clear about what you want to have? Can you also tell us what you have done so far? –  brothers28 Feb 2 at 13:19
    
I want to build a tree structure I want to put the last two objects into the first object children array –  Mohamed Hana Feb 2 at 13:21
    
Then have a look at this post here stackoverflow.com/questions/18017869/… –  brothers28 Feb 2 at 13:25

1 Answer 1

up vote 0 down vote accepted
arrayOfObjects.forEach(function(obj) {
    console.log(obj.parent_id);
    arrayOfObjects[0].children.push(obj.text);
    arrayOfObjects[0].children.push(obj.value);
});
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.