Skip to content
Subhajit Sahu edited this page Dec 8, 2022 · 12 revisions

Exchange two values in an object.

Alternatives: swap, swap$.
Similar: get, set, swap, remove.


function swap(x, k, l)
// x: an object
// k: a key
// l: another key
const object = require('extra-object');

var x = {a: 1, b: 2, c: 3, d: 4};
object.swap(x, 'a', 'b');
// → { a: 2, b: 1, c: 3, d: 4 }

object.swap(x, 'a', 'd');
// → { a: 4, b: 2, c: 3, d: 1 }


References

Clone this wiki locally