A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript-array-of-method/ below:

JavaScript Array of() Method - GeeksforGeeks

JavaScript Array of() Method

Last Updated : 15 Jul, 2024

The Javascript array.of() method is an inbuilt method in JavaScript that creates a new array instance with variables present as the argument of the method.

Syntax:
Array.of(element0, element1, ....)
Parameters:  Return Value: 

Example 1: Creating an Array with Numbers.

In this example, Creates an array with the numbers 1 to 5 using Array.of().

JavaScript
let numbersArray = Array.of(1, 2, 3, 4, 5);
console.log(numbersArray); 

Example 2: Creating an Array with Different Types of Elements

In this example, Creates an array with mixed types: number, string, boolean, object, and array.

JavaScript
let mixedArray = Array.of(10, 'hello', true, { name: 'John' }, [1, 2, 3]);
console.log(mixedArray); 

Output
[ 10, 'hello', true, { name: 'John' }, [ 1, 2, 3 ] ]

Example 3: Creating an Array with Undefined and Null Values

In this example, Creates an array containing special values: undefined, null, NaN, and Infinity.

JavaScript
let specialValuesArray = Array.of(undefined, null, NaN, Infinity);
console.log(specialValuesArray); 

Output
[ undefined, null, NaN, Infinity ]
Supported Browsers:

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4