assocSet.js 450 B

1234567891011121314151617181920
  1. import assocIndexOf from './assocIndexOf';
  2. /**
  3. * Sets the associative array `key` to `value`.
  4. *
  5. * @private
  6. * @param {Array} array The array to modify.
  7. * @param {string} key The key of the value to set.
  8. * @param {*} value The value to set.
  9. */
  10. function assocSet(array, key, value) {
  11. var index = assocIndexOf(array, key);
  12. if (index < 0) {
  13. array.push([key, value]);
  14. } else {
  15. array[index][1] = value;
  16. }
  17. }
  18. export default assocSet;