0

I need to swap the first row and second row by using jquery on button click. Is there any json predefined function to swap two array of json.

  var arr = [
           { "ID": 135, "Name": "Fargo Chan", "Address": "34, Baker Street" },
           { "ID": 432, "Name": "Aaron Luke", "Address": "BLDG 1, J Street" },
           { "ID": 252, "Name": "Dilip Singh", "Address": "Hotel J, SE" }
         ];

  var arr = [
          { "ID": 432, "Name": "Aaron Luke", "Address": "BLDG 1, J Street" },
          { "ID": 135, "Name": "Fargo Chan", "Address": "34, Baker Street" },     
          { "ID": 252, "Name": "Dilip Singh", "Address": "Hotel J, SE" }
       ];
ipln
  • 113
  • 1
  • 2
  • 14
  • `var arr = [ { "ID": 135, "Name": "Fargo Chan", "Address": "34, Baker Street" }, { "ID": 432, "Name": "Aaron Luke", "Address": "BLDG 1, J Street" }, { "ID": 252, "Name": "Dilip Singh", "Address": "Hotel J, SE" } ]; var temp = arr[0]; arr[0] = arr[1]; arr[1] = temp;` – Tushar Aug 04 '15 at 10:32
  • Another duplicate with a nicer solution: http://stackoverflow.com/questions/5306680/move-an-array-element-from-one-array-position-to-another – Rory McCrossan Aug 04 '15 at 10:34
  • hi rory, here i need to swap array of json but that you shared link as array values.. – ipln Aug 04 '15 at 10:36

0 Answers0