Skip to main content
deleted 10 characters in body
Source Link
Richie Bendall
  • 9.4k
  • 4
  • 51
  • 66

You can use relative indexing with array.prototype.atArray#at:

const myArray = [1, 2, 3] console.log(myArray.at(-1)) // => 3 

You can use relative indexing with array.prototype.at:

const myArray = [1, 2, 3] console.log(myArray.at(-1)) // => 3 

You can use relative indexing with Array#at:

const myArray = [1, 2, 3] console.log(myArray.at(-1)) // => 3 
Update with regards to browser shipping
Source Link
Richie Bendall
  • 9.4k
  • 4
  • 51
  • 66

The Array.prototype.at proposal (stage 3) adds a method forYou can use relative indexing with (MDNarray.prototype.at):

const myArray = [1, 2, 3] console.log(myArray.at(-1)) // => 3 

Another TC39 proposal, the Array.prototype.lastItem proposal (stage 1), adds a getter that returns the last item in an array:

const myArray = [1, 2, 3] console.log(myArray.lastItem) // => 3 

The .at proposal is currently only implemented in pre-release versions of Firefox and Safari.

.lastItem is not supported in any browser, and the proposal’s champion currently considers withdrawing the proposal.

The Array.prototype.at proposal (stage 3) adds a method for relative indexing (MDN):

const myArray = [1, 2, 3] console.log(myArray.at(-1)) // => 3 

Another TC39 proposal, the Array.prototype.lastItem proposal (stage 1), adds a getter that returns the last item in an array:

const myArray = [1, 2, 3] console.log(myArray.lastItem) // => 3 

The .at proposal is currently only implemented in pre-release versions of Firefox and Safari.

.lastItem is not supported in any browser, and the proposal’s champion currently considers withdrawing the proposal.

You can use relative indexing with array.prototype.at:

const myArray = [1, 2, 3] console.log(myArray.at(-1)) // => 3 
Moved candidate proposal up; added note about browser support and future of `.lastItem` proposal.
Source Link
Sebastian Simon
  • 19.8k
  • 8
  • 61
  • 88

Not implemented yet!

The new TC39 Array.prototype.lastItem proposalArray.prototype.at proposal (stage 13) adds a getter that returns the last item in an arraymethod for relative indexing (MDN):

const myArray = [1, 2, 3] console.log(myArray.lastItemat(-1)) // => 3 

TheAnother TC39 proposal, the Array.prototype.at proposalArray.prototype.lastItem proposal (stage 31), adds a different API (MDN)getter that returns the last item in an array:

const myArray = [1, 2, 3] console.log(myArray.at(-1)lastItem) // => 3 

The .at proposal is currently only implemented in pre-release versions of Firefox and Safari.

.lastItem is not supported in any browser, and the proposal’s champion currently considers withdrawing the proposal.

Not implemented yet!

The new TC39 Array.prototype.lastItem proposal (stage 1) adds a getter that returns the last item in an array:

const myArray = [1, 2, 3] console.log(myArray.lastItem) //=> 3 

The Array.prototype.at proposal (stage 3) adds a different API (MDN):

const myArray = [1, 2, 3] console.log(myArray.at(-1)) //=> 3 

The Array.prototype.at proposal (stage 3) adds a method for relative indexing (MDN):

const myArray = [1, 2, 3] console.log(myArray.at(-1)) // => 3 

Another TC39 proposal, the Array.prototype.lastItem proposal (stage 1), adds a getter that returns the last item in an array:

const myArray = [1, 2, 3] console.log(myArray.lastItem) // => 3 

The .at proposal is currently only implemented in pre-release versions of Firefox and Safari.

.lastItem is not supported in any browser, and the proposal’s champion currently considers withdrawing the proposal.

added 113 characters in body
Source Link
Richie Bendall
  • 9.4k
  • 4
  • 51
  • 66
Loading
added 9 characters in body
Source Link
Richie Bendall
  • 9.4k
  • 4
  • 51
  • 66
Loading
edited body
Source Link
Richie Bendall
  • 9.4k
  • 4
  • 51
  • 66
Loading
Add Array.prototype.item proposal
Source Link
Richie Bendall
  • 9.4k
  • 4
  • 51
  • 66
Loading
Show that the feature hasn't been implemented yet.
Source Link
Richie Bendall
  • 9.4k
  • 4
  • 51
  • 66
Loading
Source Link
Richie Bendall
  • 9.4k
  • 4
  • 51
  • 66
Loading