1
"default_tabs" : [ 
    {
        "value" : "Ice"
    }, 
    {
        "value" : "Gold"
    } 
 ]

I want to assign this values into another array in such a way that it should look like below

selected_values :  [{"values" : { "Ice" : "Edit","Gold" : "Edit" },"role" : "Admin"}]

for this i prepared the below,

 default_tabs.forEach(function(i,v){
       selected_values.push('values':v)
    }) 

I know i am wrong can anyone help me please.Thanks.

1
  • Your format is invalid. I can't tell if you want values as an array or an object array? Commented Jan 14, 2017 at 12:25

1 Answer 1

1

You could iterate the array and add the properties to the first item of result.selected_values's property values.

var object = { default_tabs: [{ value: "Ice" }, { value: "Gold" }] },
    result = { selected_values: [{ values: {}, role: "Admin" }] };

object.default_tabs.forEach(function (a) {
    result.selected_values[0].values[a.value] = 'Edit';
});

console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }

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

3 Comments

Hi Nina ..really impressed with your technique of using arrays,Thanks a lot.If can,please suggest me some best articles for arrays.
@nlr_p, for a start, you could have a look into the documentation from MDN about Arrays.
Ok,Thank you ...:)

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.