2

Here is my JSON Array.

 rows : [
   { 
     "id":1,
     "first_name":"William",
     "last_name":"Elliott",
     "email":"[email protected]",
     "country":"Argentina",
     "ip_address":"247.180.226.89",
     "notificationType": [
       {
         "type": "update",
         "text": "New Update"
         "selected":null
       },
       {
         "type": "user",
         "text": "New User"
         "selected":null           
       }
     ]
   }
 ]

I need to update this array.For example let's take care of notificationType data.

I want to update "selected":null value to "selected":true.

How can I do this?

1 Answer 1

2

Just loop through your data, e.g.:

var data = {
    rows: [ {
            'id': 1,
            'first_name': 'William',
            'last_name': 'Elliott',
            'email': '[email protected]',
            'country': 'Argentina',
            'ip_address': '247.180.226.89',
            'notificationType': [
                { 'type': 'update', 'text': 'New Update', 'selected': null },
                { 'type': 'user', 'text': 'New User', 'selected': null }
            ]
        } 
    ]
};

data.rows.forEach(function(row) {
    row.notificationType.forEach(function(notif) {
        notif.selected = true;
    });
});

or if you want to update particular notification:

data.rows[0].notificationType[1].selected = true;
//--------^ row index
//----------------------------^ notification index
Sign up to request clarification or add additional context in comments.

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.