Javascript Array

From Yate Documentation
Revision as of 19:23, 8 October 2020 by Andreea (Talk | contribs)

Jump to: navigation, search

Javascript Array.

Contents

Constructor

Static Methods

Methods

  • push(element)

Adds new items to the end of an array.
Parameters:
element - The element to be added at the end of the array.
Return:
The new length.

Note: this method will change the original array.

Ex:
var test_arr = [1,2];
var res = testarr.push(3);
// test_arr -> 1,2,3
// res -> 3
  • pop()

Removes the last element of an array.
Return:
The removed element.
Note: this method will change the original array.

  • concat(array1)
  • concat(array1,array2,...)

Join two or more arrays.

Note: This method does not change the existing arrays, but returns a new array, containing the values of the joined arrays.

Ex: 
array1 = [1,2]
array2 = [2,3,4]
array3 = [4,5]
var res = array1.concat(array2, array3);
//res -> [1,2,2,3,4,4,5]
  • join()
  • join(separator)

The elements will be separated by a specified separator. The default separator is comma (,).

Note: This method will not change the original array.

  • reverse()

Reverses the order of the elements in an array.

Note: this method will change the original array.

  • shift()
  • unshift()
  • slice()
  • splice()
  • sort()
  • includes()
  • indexOf()
  • lastIndexOf()

Properties

  • length

Returns the number of elements in an array.

Personal tools
Namespaces

Variants
Actions
Preface
Configuration
Administrators
Developers