0

I have the following JSON. I need to swap SortId

Like I have this,

[{"CategoryId":1,"Name":"Worktable","SortId":1}
,{"CategoryId":2,"Name":"Bf ","SortId":2}]

After swaping their 'SortId' I need

[{"CategoryId":1,"Name":"Worktable","SortId":2}
,{"CategoryId":2,"Name":"Bf ","SortId":1}]

Please tell me how to do it through JavaScript.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Minhaj
  • 156
  • 1
  • 9

1 Answers1

1
var tmp = a[0].SortId;
a[0].SortId = a[1].SortId;
a[1].SortId = tmp;

jsFiddle

Andrew
  • 5,290
  • 1
  • 19
  • 22