-1

I want to insert key & Object in array.

JQuery code:

  var steps = [];
  var RequestParams = {};
  RequestParams.ActionName = 'aname';
  steps.push({ Name:'abc'} ,RequestParams);

My output

"steps": [
            { "Name": "abc" },
            {  
             ActionName :"aname"
             },
  ]

Expected:

"steps": [
            { "Name": "abc",
            "RequestParams": {
             ActionName :"aname"
             },
  ]
0

2 Answers 2

1
steps.push({"Name": "abc", "RequestParams": RequestParams});

What you want to achieve is having inside your steps array a javascript object with a property Name that has value "abc", and a property named RequestParams that has the value of your RequestParamsvariable.

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

3 Comments

Is it possible without hard coding?
@user3194721 what do you mean by "hard coding"? What are you using then?
I'd say no, AFAIK javascript doesn't have any reflection mechanism to use the name of the variable inside a script, so you have to hardcode the RequestParam name of the property. See also stackoverflow.com/questions/9795773/…
0

Should be

steps.push({ Name:'abc' } ,{ RequestParams:RequestParams });

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.