JavaScript Arrays for Pythonistas (Summary)

Your Python list skills now carry the support team’s on-call rota into JavaScript. In the Monday rota project, you rotated the queue, handled leave and a new hire, and kept the wiki’s alphabetical view separate from the real order. In Finish the Pager Report, you completed the script with last week’s count and the three busiest weeks, preserving the counts in week order.

You can now port a script that builds, reads, edits, searches, and sorts an ordered collection. The familiar zero-based positions carry over. The decisions about changing the collection deserve more care.

Choose Whether to Change the Array

Keep asking “Does this change my array?” The rota’s order decides who carries the pager, while the wiki and escalation list need separate views. These are the tools you used:

  • Read with rota[0], rota.at(-1), and .length, replacing Python’s negative bracket indexing and len().
  • Add or remove at the ends with .push(), .pop(), .shift(), and .unshift().
  • Copy with .slice(), join arrays with .concat(), and reverse a copy with .toReversed().
  • Edit in place with .splice(), reading its arguments as where to start, how many items to remove, and what to insert.
  • Search names with .includes() or .indexOf(), checking for -1 before removing a match.
  • Sort a copy with .toSorted(), supplying a numeric comparison function for page counts.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.