/planets-js

planets-array.js. Some practice with array methods.

Primary LanguageJavaScript

planets-js

planets-array.js. Some practice with array methods.

alt text

Steps in js

  1. Created an array of planets
  2. Created a function for logging the planets array
  3. .unshift method. Added "The Sun" to the beginning of the planets array
  4. .push method. Added "Pluto" to the end of the planets array
  5. .shift method. Removed "The Sun" from the beginning of the planets array.
  6. .pop method. Removed "Pluto" from the end of the planets array.
  7. .indexOf method. Found and logged the index of "Venus" in the planets array.
  8. .splice method(remove). Created an index of pre-sliced element, then used the splice method to remove the planet after "Venus".
  9. .splice method(add). Used splice to add back the planet after "Venus".
  10. .reverse method. Reversed the order of the planets array.
  11. .sort method. sorted the planets array.