logoZlata Son


Lesson 1

"JavaScript Array Methods"
    Home work Lesson 1:
  • Зробити хоча б 5 прикладів використання методів об'єкту Array.

if you want to see the result in the console click "Ctrl+Shift+J" or F12


  • The join() method joins array elements into a string. Example array: ["Green", "Orange", "Blue", "Indigo", "Olive", "Purple"]

    Green *** Orange *** Blue *** Indigo *** Olive *** Purple
  • The shift() method returns the string that was "shifted out". The unshift() method returns the new array length. Example array: ["Black", "Yellow", "Red", "Silver", "Coral", "Indigo", "Purple"]

    Lime,White,Yellow,Red,Silver,Coral,Indigo,Purple
  • The splice() method can be used to add new items to an array. Example array: ["Coral", "Blue", "Gray", "Pink", "Violet", "Aqua"]

    Coral,Red,Fuchsia,Pink,Violet,Aqua
  • The concat() method creates a new array by concatenating two arrays. Example array 1: ["Apricot", "Cherry", "Grape", "Kiwi"] ; and array 2: ["Broccoli", "Carrot", "Pea", "Tomato"]

    Apricot,Cherry,Grape,Kiwi,Broccoli,Carrot,Pea,Tomato
  • The pop() method removes the last element from an array. The push() method adds a new element to an array (at the end). Example array: ["Banana", "Apricot", "Cherry", "Grape"]

    Banana,Apricot,Cherry,Mango
  • The sort() method sorts an array alphabetically. The reverse() method reverses the elements in an array. Example array: ["Pea", "Tomato", "Broccoli", "Carrot"]

    Tomato,Pea,Carrot,Broccoli
  • The slice() method slices out a piece of an array into a new array. Example array: ["Azalea", "Begonia", "Crocus", "Daisy", "Freesia", "Hibiscus"]

    Azalea,Begonia,Crocus,Daisy,Freesia,Hibiscus

    Crocus,Daisy,Freesia,Hibiscus
  • The valueOf() method is the default behavior for an array. The method toString() converts an array to a string of (comma separated) array values.Example array: ["Iris", "Lotus", "Orchid"]

    Iris,Lotus,Orchid- valueOf
    Iris,Lotus,Orchid- toString
  • The split() string method is used to split a string into an array of substrings, and returns the new array. Example string: 'Peony, Roses, Tulip'

    Peony,Roses,Tulip