I feel that a lot of practical features have been added to the expansion of arrays, and they feel quite important
1. Array.of() converts data variables into Array form
{ let arr = Array.of(3,4,7,9,11); console.log('arr=',arr);//[3,4,7,9,11] let empty=Array.of();//[] console.log('empty',empty); }
2. Array.from() is used to convert two types of objects into real arrays: Array-like objects (array-like object) and traversable (iterable) objects (including ES6’s new data structures Set and Map)
At the same time Array. from
can also accept a second parameter, which is similar to the map
method of an array. It is used to process each element and put the processed value into the returned array.
{ let p=document.querySelectorAll('p'); let pArr=Array.from(p); pArr.forEach(function(item){ console.log(item.textContent); }); console.log(Array.from([1,3,5],function(item){return item*2}));//[2,6,10] }
3. fill(data,startIndex,endIndex-1) fills the array. If there is only one data parameter, all will be replaced. If there are three parameters Replace all startIndex~endIndex-1 with data
{ console.log('fill-7',[1,'a',undefined].fill(7));//[7,7,7] console.log('fill,pos',['a','b','c'].fill(7,1,3)); }
4. keys (return all array subscripts) values (return all values of the array) entries (Including all keys and values)
{ for(let index of ['1','c','ks'].keys()){ console.log('keys',index); } for(let value of ['1','c','ks'].values()){ console.log('values',value); } for(let [index,value] of ['1','c','ks'].entries()){ console.log('values',index,value); } }
5. copyWithin(p1,p2,p3) From The p1 position starts to be overwritten with the data from p2 to p3-1
{ console.log([1,2,3,4,5].copyWithin(0,3,4));//[4,2,3,4,5] }
6. find() stops when it finds the first value that meets the conditions and findIndex() stops when it finds the index of the first qualified value
{ console.log([1,2,3,4,5,6].find(function(item){return item>3}));//4 console.log([1,2,3,4,5,6].findIndex(function(item){return item>3})); }
{ console.log('number',[1,2,NaN].includes(1));//true console.log('number',[1,2,NaN].includes(NaN));//true }
The above is the detailed content of Detailed explanation of new feature examples of array extension. For more information, please follow other related articles on the PHP Chinese website!

PHP的SNMP扩展是一种使PHP能够通过SNMP协议与网络设备进行通信的扩展程序。使用该扩展可以方便地获取和修改网络设备的配置信息,例如路由器、交换机等设备的CPU、内存、网络接口等信息,也可以进行诸如开关设备端口等控制操作。本文将介绍SNMP协议的基础知识、PHP的SNMP扩展的安装方法以及如何在PHP中使用SNMP扩展进行网络设备的监控和控制。一、SN

如何使用极光推送扩展,在PHP应用中实现批量消息推送功能在移动应用的开发中,消息推送是一项非常重要的功能。极光推送是一种常用的消息推送服务,提供了丰富的功能和接口。本文将介绍如何使用极光推送扩展在PHP应用中实现批量消息推送功能。第一步:注册极光推送账号并获取API密钥首先,我们需要在极光推送官网(https://www.jiguang.cn/push)注册

PHP是一种流行的服务器端语言,可以用来开发Web应用程序和处理文件。PHP的ZipArchive扩展是一个强大的工具,可以在PHP中操作zip文件。在这篇文章中,我们将介绍如何使用PHP的ZipArchive扩展来创建、读取和修改zip文件。一、安装ZipArchive扩展在使用ZipArchive扩展之前,需要确保已经安装了这个扩展。安装方法如下:1.安

随着PHP的发展和应用场景的不断扩大,Phar扩展已经成为PHP编程中的重要一环。Phar是PHPArchive的缩写,它可以将多个PHP文件和资源打包成单个文件,方便进行分发和管理。本文将介绍如何使用PHP的Phar扩展来进行打包和管理。安装Phar扩展首先,我们需要检查PHP是否已经安装Phar扩展。在Linux下,通过终端输入以下命令:php-m

PHP的POSIX扩展是一组允许PHP与POSIX兼容操作系统进行交互的函数和常量。POSIX(PortableOperatingSystemInterface)是一组操作系统接口标准,旨在允许软件开发人员编写可在各种UNIX或UNIX类操作系统上运行的应用程序。本文将介绍如何使用PHP的POSIX扩展,包括安装和使用。一、安装PHP的POSIX扩展在

随着前端技术的不断发展,Vue已经成为了前端开发中的热门框架之一。在Vue中,组件是其中的核心概念之一,它可以将页面分解为更小,更易管理的部分,从而提高开发效率和代码复用性。本文将重点介绍Vue如何实现组件的复用和扩展。一、Vue组件复用mixinsmixins是Vue中的一种共享组件选项的方式。Mixins允许将多个组件的组件选项合并成一个对象,从而最大

PHP和WebDriver扩展:如何模拟用户点击和输入操作近年来,随着Web应用程序的快速发展,自动化测试变得越来越重要。在自动化测试中,模拟用户操作是一个关键的环节,它可以使我们更准确地测试和验证我们的应用程序。在PHP开发中,我们通常使用SeleniumWebDriver来实现自动化测试。SeleniumWebDriver是一种强大的工具,它可以模拟

教程:使用百度云推送(BaiduPush)扩展在PHP应用中实现消息推送功能引言:随着移动应用的迅猛发展,消息推送功能在应用程序中变得越来越重要。为了实现即时通知和消息推送功能,百度提供了一种强大的云推送服务,即百度云推送(BaiduPush)。在本教程中,我们将学习如何使用百度云推送扩展(PHPSDK)在PHP应用中实现消息推送功能。我们将使用百度云


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools
