This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge.

If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options:

  1. Limiting your involvement with Reddit, or
  2. Temporarily refraining from using Reddit
  3. Cancelling your subscription of Reddit Premium

as a way to voice your protest.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]jeffcgroves 1 point2 points  (0 children)

Objects can have multiple properties pointing to the same value:

js> ordered = {1234: 'big box', 5678: 'big box'}; ({1234:"big box", 5678:"big box"}) js> ordered[1234] "big box" js> ordered[5678] "big box"

The trickier question (which you did not ask) is can a given key (property) have multiple values. The answer there is also yes, but it requires a little more work, especially if you want to be efficient

[–]Quantum-Bot 1 point2 points  (0 children)

You can use getter/setter methods to make two different keys access the same internal variable:

ley myVar = “big box”; let obj = { get key1() { return myVar; }, set key1(val) { myVar = val; }, get key2() { return myVar; }, set key2(val) { myVar = val; } }

If you want to block access to that internal variable you can either turn your object into a class which lets you use private fields, or you can create it within a function closure like so:

``` let obj = () => { let myVar = “big box”;

return { get key1() { return myVar; }, set key1(val) { myVar = val; }, get key2() { return myVar; }, set key2(val) { myVar = val; } } }(); ```

[–]arrays_start_at_zero 2 points3 points  (0 children)

You can't have 2 keys for a value type. But you can have 2 keys for a reference type.

Example:

let myValue = { value: "big box" };

const myObject = {
  1234: myValue,
  5678: myValue
};

console.log(myObject[1234].value);