Get the App
SLTechnology News&Howtos  ›  Development  › 

The concrete usage of Array Operation method in JS

Shulou Source: shulou.com Published: 2022-06-03 17:29:02 11月13日 Update

This article mainly explains "the specific usage of Array operation method in JS". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the specific usage of Array operation method in JS.

1. Array.from () creates a new array instance from a similar array or iterable object.

Console.log (Array.from ("foo")); / / expected output: Array ["f", "o", "o"] console.log (Array.from ([1,2,3], (x) = > x + x)); / / expected output: Array [2,4,6]

2. Array.isArray () is used to determine whether the value passed is an Array.

Array.isArray ([1,2,3]); / / trueArray.isArray ({foo: 123}); / / falseArray.isArray ("foobar"); / / falseArray.isArray (undefined); / / false

3. Array.of () creates a new array instance with variable number parameters.

Regardless of the number or type of parameters.

Array.of (7); / / [7] Array.of (1,2,3); / / [1,2,3] Array (7); / / [,] Array (1,2,3); / / [1,2,3] / / es5if (! Array.of) {Array.of = function () {return Array.prototype.slice.call (arguments);} } at this point, I believe you have a deeper understanding of "the specific use of Array operation methods in JS". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Methods arrays content parameters instances quantity learning practicality deeper interest practicality practicality objects simple operation more friends types websites channels Zhongchuang Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Tech Info Shulou Technology Redmi Apple