Arrays JavaScript Objects JavaScript

 Arrays

The Array object, as with arrays in other programming languages, enables storing a collection of multiple items under a single variable name and has members for performing common array operations.

Description

In JavaScript, arrays aren't primitives but are instead Array objects with the following core characteristics:

JavaScript arrays are resizable and can contain a mix of different data types. (When those characteristics are undesirable, use typed arrays instead.)

JavaScript arrays are not associative arrays and so, array elements cannot be accessed using arbitrary strings as indexes, but must be accessed using nonnegative integers (or their respective string form) as indexes.

JavaScript arrays are zero-indexed: the first element of an array is at index 0, the second is at index 1, and so on — and the last element is at the value of the array's length property minus 1.

JavaScript array-copy operations create shallow copies. (All standard built-in copy operations with any JavaScript objects create shallow copies, rather than deep copies).

Array = Object in js 

Constructor

Array()

Creates a new Array object.


Static properties

get Array[@@species]

Returns the Array constructor.


Static methods

Array.from()

Creates a new Array instance from an array-like object or iterable object.


Array.isArray()

Returns true if the argument is an array, or false otherwise.


Array.of()

Creates a new Array instance with a variable number of arguments, regardless of number or type of the arguments.


Instance properties

Array.prototype.length

Reflects the number of elements in an array.


Array.prototype[@@unscopables]

Contains property names that were not included in the ECMAScript standard prior to the ES2015 version and that are ignored for with statement-binding purposes.


Instance methods

Array.prototype.at()

Returns the array item at the given index. Accepts negative integers, which count back from the last item.


Array.prototype.concat()

Returns a new array that is the calling array joined with other array(s) and/or value(s).


Array.prototype.copyWithin()

Copies a sequence of array elements within an array.


Array.prototype.entries()

Returns a new array iterator object that contains the key/value pairs for each index in an array.


Array.prototype.every()

Returns true if every element in the calling array satisfies the testing function.


Array.prototype.fill()

Fills all the elements of an array from a start index to an end index with a static value.


Array.prototype.filter()

Returns a new array containing all elements of the calling array for which the provided filtering function returns true.


Array.prototype.find()

Returns the value of the first element in the array that satisfies the provided testing function, or undefined if no appropriate element is found.


Array.prototype.findIndex()

Returns the index of the first element in the array that satisfies the provided testing function, or -1 if no appropriate element was found.


Array.prototype.findLast()

Returns the value of the last element in the array that satisfies the provided testing function, or undefined if no appropriate element is found.


Array.prototype.findLastIndex()

Returns the index of the last element in the array that satisfies the provided testing function, or -1 if no appropriate element was found.


Array.prototype.flat()

Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth.


Array.prototype.flatMap()

Returns a new array formed by applying a given callback function to each element of the calling array, and then flattening the result by one level.


Array.prototype.forEach()

Calls a function for each element in the calling array.


Array.prototype.group() Experimental

Groups the elements of an array into an object according to the strings returned by a test function.


Array.prototype.groupToMap() Experimental

Groups the elements of an array into a Map according to values returned by a test function.


Array.prototype.includes()

Determines whether the calling array contains a value, returning true or false as appropriate.


Array.prototype.indexOf()

Returns the first (least) index at which a given element can be found in the calling array.


Array.prototype.join()

Joins all elements of an array into a string.


Array.prototype.keys()

Returns a new array iterator that contains the keys for each index in the calling array.


Array.prototype.lastIndexOf()

Returns the last (greatest) index at which a given element can be found in the calling array, or -1 if none is found.


Array.prototype.map()

Returns a new array containing the results of invoking a function on every element in the calling array.


Array.prototype.pop()

Removes the last element from an array and returns that element.


Array.prototype.push()

Adds one or more elements to the end of an array, and returns the new length of the array.


Array.prototype.reduce()

Executes a user-supplied "reducer" callback function on each element of the array (from left to right), to red.


JavaScript Objects

You have already learned that JavaScript variables are containers for data values.

Introduction to the JavaScript objects

In JavaScript, an object is an unordered collection of key-value pairs. Each key-value pair is called a property.

The key of a property can be a string. And the value of a property can be any value, e.g., a string, a number, an array, and even a function.

JavaScript provides you with many ways to create an object. The most commonly used one is to use the object literal notation.

The following example creates an empty object using the object literal notation:







Comments

Popular posts from this blog

Events Js