Урок - ArrayObject

Главная » Курсы » Курс ACMF » Урок - ArrayObject

Обучающий онлайн курс
ACMF

Лицензия: Лицензия Creative Commons.

Properties

  • ArrayObject::length - contains the number of elements in the array.

Methods

  • ArrayObject::clear():this - clears ArrayObject and returns this.
  • ArrayObject::clone():ArrayObject - clones ArrayObject.
  • ArrayObject::copy(Position[, Count]):ArrayObject - returns elements from position (and count) as ArrayObject without deleting.
  • ArrayObject::count():Count - returns items count in ArrayObject.
  • ArrayObject::cut(Position[, Count = 1):ArrayObject - deletes elements by position (and count) and returns them as ArrayObject.
  • ArrayObject::delete(Position[, Count = 1):this - deletes element by position number (and count) and return this.
  • ArrayObject::first([Mixed default]):Mixed - returns first element from ArrayObject without removing.
  • ArrayObject::firstN([Count = 1]):ArrayObject - returns first Count elements from ArrayObject without removing.
  • ArrayObject::get(Position) - returns value by position number from ArrayObject without removing.
  • ArrayObject::has(Position) - returns true if element with position number exists.
  • ArrayObject::keys() - returns keys as ArrayObject.
  • ArrayObject::last() - returns last element from ArrayObject without removing.
  • ArrayObject::lastN([Count = 1]):ArrayObject - returns last Count element from ArrayObject without removing.
  • ArrayObject::lead(Mixed) - inserts element at the begin.
  • ArrayObject::map(Callback[, args]) - apply callback function to each element.
  • ArrayObject::pop():Mixed - returns last element and remove it.
  • ArrayObject::popN([Count = 1]):ArrayObject - returns last Count elements and remove it.
  • ArrayObject::push(Mixed) - inserts element at the end.
  • ArrayObject::remove(Position[, Default]):Mixed - deletes element by position and returns it.
  • ArrayObject::set(Position, Mixed) - update element by position number.
  • ArrayObject::turn(Default):Mixed - removes first element and returns it.
  • ArrayObject::turnN([Count = 1]):ArrayObject - removes first Count elements and returns it.
  • ArrayObject::toPHPArray() - returns array as PHP Array.
  • ArrayObject::values() - returns values.

Examples

Delete first element.

Using Array.turn() method:

el = a.turn()
el = a.turn(default)

Using Array.delete() method:

a.delete(1)

Using Array.remove() method:

el = a.remove(1)
el = a.remove(1, default)

Delete last element.

Using Array.pop() method:

el = a.pop()
el = a.pop(default)

Using Array.delete() method:

a.delete(a.length)
a.delete(-1)

Using Array.remove() method:

el = a.remove(a.length)
el = a.remove(a.length, default)
el = a.remove(-1)
el = a.remove(-1, default) 

Delete any element.

Using Array.delete() method:

a.delete(2)

Using Array.remove() method:

el = a.remove(3)
el = a.remove(4, default)

Delete a few elements.

Using Array.delete() method:

a.delete(2, 5)

Using Array.cut() method:

a.cut(2, 5)

 

Lodash Replacement

_.take(array, [n=1])

ArrayObject::firstN([Count = 1]):ArrayObject - returns first Count elements from ArrayObject without removing.
ArrayObject::turnN([Count = 1]):ArrayObject - removes first Count elements and returns it.
ArrayObject::first() - returns the first element without deleting.
ArrayObject::turn() - deletes and returns the first element.
ArrayObject::copy(1, Count) - returns first elements without deleting.
ArrayObject::copyFirst(Count) - returns first Count elements without deleting.

_.takeRight(array, [n=1])

ArrayObject::lastN([Count = 1]):ArrayObject - returns last Count element from ArrayObject without removing.
ArrayObject::popN([Count = 1]):ArrayObject - returns last Count elements and remove it.
ArrayObject::last() - returns last element from ArrayObject without removing.
ArrayObject::pop():Mixed - returns last element and remove it.
ArrayObject::copy(Position[, Count]):ArrayObject - returns elements from position (and count) as ArrayObject without deleting.

_.takeRightWhile(array, [predicate=_.identity])

No

_.takeWhile(array, [predicate=_.identity])

No