Javascript Array

From Yate Documentation
(Difference between revisions)
Jump to: navigation, search
(Created page with "Javascript Array. == Constructor == == Methods == * '''push()'''<br> * '''pop()'''<br> * '''concat()'''<br> * '''join()'''<br> * '''reverse()'''<br> * '''shift()'''<br...")
 
Line 2: Line 2:
  
 
== Constructor ==
 
== Constructor ==
 +
 +
== Static Methods ==
  
 
== Methods ==
 
== Methods ==
  
* '''push()'''<br>
+
* '''push(element)'''<br>
 +
 
 +
Adds new items to the end of an array.<br>
 +
Parameters:<br>
 +
element - The element to be added at the end of the array.<br>
 +
Return:<br>
 +
The new length.<br>
 +
 
 +
Note: this method will change the original array.<br>
 +
 
 +
Ex:<br>
 +
var test_arr = [1,2];<br>
 +
var res = testarr.push(3);<br>
 +
// test_arr -> 1,2,3<br>
 +
// res -> 3<br>
  
 
* '''pop()'''<br>
 
* '''pop()'''<br>
 +
Removes the last element of an array.<br>
 +
Return:<br>
 +
The removed element.<br>
 +
Note: this method will change the original array.<br>
  
* '''concat()'''<br>
+
* '''concat(array1)'''<br>
 +
* '''concat(array1,array2,...)'''<br>
 +
 
 +
Join two or more arrays.<br>
 +
 
 +
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()'''<br>
 
* '''join()'''<br>
 +
* '''join(separator)'''<br>
 +
 +
The elements will be separated by a specified separator. The default separator is comma (,).
 +
 +
Note: This method will not change the original array.
  
 
* '''reverse()'''<br>
 
* '''reverse()'''<br>
 +
Reverses the order of the elements in an array.
  
 +
Note: this method will change the original array.
 
* '''shift()'''<br>
 
* '''shift()'''<br>
  
Line 34: Line 73:
  
 
* '''length'''<br>
 
* '''length'''<br>
 +
Returns the number of elements in an array.

Revision as of 19:23, 8 October 2020

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