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
  • 756,363
  • 169
  • 1,062
  • 1,111
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,228
  • 1
  • 16
  • 22