I have a parent array lines = [] and contains a number of objects in lines.push(data); . The data is read line by line in my node application.
And i split each line whenever \ slash character is found. Then change line into Objects data = {} and properties data.marker; data.value; data.children and so. Now when a line which has several \ slash characters is found i want that data.children to be a child array of objects.
This is the line data after split()
[ 'ft Some older versions read, ',
'fqa And we are writing these things to you so that your joy will be complete. ',
'fqb ',
'f*' ]
and this is my code to convert into data.children array
data.children = [];
//object for child
var obj = {};
for (var j=0; j<childArr.length; j++) {
obj.marker = childArr[j].split(" ")[0] ;
obj.value = childArr[j].substr(childArr[j].indexOf(' ')+1) ;
}
data.children.push(obj);
Now when i check console.log(data.children) this is what i gets
[ { marker: 'f*', value: 'f*' }]
instead of what i need is
[ { marker: 'ft' , value: 'Some older versions read,' },
{ marker: 'fqa', value: 'And we are writing these things to you so that your joy will be complete.' },
{ marker: 'fqb', value: 'null' },
{ marker: 'f*', value: 'null' },]
I am sure that it will be some trouble while i am pushing data into children array. Any help will be appreciated! Thanks in advance.
{ marker: 'f*', value: 'f*' }obj... but it is the sameobjevery time you push ... you need to create a new object every iteration ... @War's answer is 90% correct ... a couple=should be: