Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

JavaScript Array.at()

node v17.9.1
version: 2.0.0
endpointsharetweet
// Before const array = [0, 1,2,3,4,5,6,7,8,9]; const afirstElement = array[0]; const afourthElement = array[3] const alastElement = array[array.length - 1]; const athirdLastElement = array[array.length - 3]; // After const arrayNew = [0, 1,2,3,4,5,6,7,8,9]; const bfirstElement = arrayNew.at(0); const bfourthElement = arrayNew.at(3) const blastElement = arrayNew.at(-1); const bthirdLastElement = arrayNew.at(-3); console.log({ before: { afirstElement, afourthElement, alastElement, athirdLastElement }, after: { bfirstElement, bfourthElement, blastElement, bthirdLastElement } })
Loading…

no comments

    sign in to comment