I have an array of object. One object has an array inside.
var array = [{ a:'ai', b:'bi', c:['first','second','third']}]
I need to have above array to be like this:
[
[{ a:'ai', b:'bi', c:['first','second','third'], cSplit:'first'}],
[{ a:'ai', b:'bi', c:['first','second','third'], cSplit:'second'}],
[{ a:'ai', b:'bi', c:['first','second','third'], cSplit:'third'}]
]
I tried this code:
var array = [{ a:'ai', b:'bi', c:['first','second','third']}]
var newArr = [];
for( var i=0; i<array[0]['c'].length; i++ ){
var innerArr = array;
innerArr[0]['cSplit'] = array[0]['c'][i];
newArr.push(innerArr);
}
console.log('newArr', newArr)
But it shows:
[
[{a: "ai", b: "bi", c: ['first','second','third'] , cSplit: "third"}],
[{a: "ai", b: "bi", c: ['first','second','third'] , cSplit: "third"}],
[{a: "ai", b: "bi", c: ['first','second','third'] , cSplit: "third"}]
]
Why cSplit doesn't get the first and second value?
array[0].