tc39 / proposal-slice-notation

http://tc39.es/proposal-slice-notation/
MIT License
526 stars 19 forks source link

Does the slice work against objects (non-arrays)? #48

Closed getify closed 2 years ago

getify commented 2 years ago

Is this supported?

const o = {
   a: "one",
   b: "two",
   "3": "three",
   "5": "five",
};
o[4] = "four";

o[3:5];   // [ "three", "four" ]
hax commented 2 years ago

Current proposal is minimal, only support Array and TypedArray. I think we should also support Tuple when it landed.

Note String is not supported due to unicode surrogate issue. Though I'm considering some possible solutions in follow-on proposal.

It's possible to extend to other objects in the future, but consider this proposal include negative index (or use index form end syntax instead), length property would be required, so at least it should be ArrayLike. Anyway, we could always use Array.from(arrayLike)[3:5].