Updating a JSON object using Javascript

前端 未结 9 1541
Happy的楠姐
Happy的楠姐 2020-12-07 13:37

How can i update the following JSON object dynamically using javascript or Jquery?

var jsonObj = [{\'Id\':\'1\',\'Username\':\'Ray\',\'FatherName\':\'Thompso         


        
9条回答
  •  隐瞒了意图╮
    2020-12-07 14:14

    var i = jsonObj.length;
    while ( i --> 0 ) {
        if ( jsonObj[i].Id === 3 ) {
            jsonObj[ i ].Username = 'Thomas';
            break;
        }
    }
    

    Or, if the array is always ordered by the IDs:

    jsonObj[ 2 ].Username = 'Thomas';
    

提交回复
热议问题