1

Lot of questions are available for array push and splice but not like this one.

Please see this fiddle for what i try JS Fiddle

I have the output like this

[{"rup":"100","dol":"50"},{"rup":"100","dol":"50"},{"expense":   
[{"reason":0,"cost":0,"receipt":0,"expense_type":0}]},{"expense":  
[{"reason":1,"cost":1,"receipt":1,"expense_type":1}]}]

but what i need is

[{"rup":"100","dol":"50",{"expense":[{"reason":0,"cost":0,"receipt":0,"expense_type":0}},
{"rup":"100","dol":"50",{"expense":[{"reason":1,"cost":1,"receipt":1,"expense_type":1}}]

I tried SPLICE() and ARRAY.INSERT() methods but not get like above.

Please suggest any ideas.

2 Answers 2

4

use this piece of code,

for (var i in costArray) {
    costArray[i].expense = expenseArray[i];
}

Out put:

[{"rup":"100","dol":"50","expense":{"reason":0,"cost":0,"receipt":0,"expense_type":0}},
{"rup":"100","dol":"50","expense":{"reason":1,"cost":1,"receipt":1,"expense_type":1}}]

SEE THIS FIDDLE DEMO

Sign up to request clarification or add additional context in comments.

Comments

1

The format you want in not valid in javascript, I guess you mean this:

{ "rup":"100","dol":"50", "expense":{"reason":0,"cost":0,"receipt":0,"expense_type":0} }

To get this, try replacing

 costArray.push({"expense":expenseArray});

with

costArray[i]["expense"] = expenseArray

in the second loop.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.