<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <script> /* * splice(start, deleteCount, data1, data2, data3...) * */ var arr = ['a', 'b', 'c', 'd', 'e']; //1, 3 // [8,6,4] //['a',8,6,4] //arr.splice(-5); //console.log(arr); function arrSplice(data, start, deleteCount) { // 如果start不是数字,或不能转成数字,start默认就为0 if (isNaN(start)) { start = 0; } start = Number(start); // 如果start是负数 if (start < 0) { start = data.length + start; } if (start < 0) { start = 0; } // 如果deleteCount没传 if (deleteCount == undefined) { deleteCount = data.length - start; } /* * 1. 准备一个空的数组,用于存放最后的结果 * 2. 循环源数组 * 1. 得到当前循环过程中的下标 * 2. 把这个下标和start做比较 * 1. 如果当前下标小于start,则把当前数组添加到新数组中 * 2. 否则 * 1. 是否有新增数据 * 1. 如果有新在数据,则把新增数据添加到新数组中 * 2. 否则,如果deleteCount大于0,忽略这个数据,并对deleteCount-- * 否则,把当前数据添加到新数组中 * */ var newArr = []; //新增数据 var newData = []; if (arguments.length > 3) { for (var i=3; i<arguments.length; i++) { // newData.push(arguments[i]); newData[newData.length] = arguments[i]; } } for (var i=0; i<data.length; i++) { if (i < start) { // newArr.push(data[i]); newArr[newArr.length] = data[i]; } else { if (newData.length) { //有新增数据的 // newArr = newArr.concat(newData); for (var j=0; j<newData.length; j++) { newArr[newArr.length] = newData[j]; } newData.length = 0; } if (deleteCount > 0) { deleteCount--; } else { // newArr.push(data[i]); newArr[newArr.length] = data[i]; } } } data = newArr; console.log(data); } </script> </body> </html>
The above is the detailed content of JS native array splice method instance. For more information, please follow other related articles on the PHP Chinese website!

Best practices for H5 code include: 1. Use correct DOCTYPE declarations and character encoding; 2. Use semantic tags; 3. Reduce HTTP requests; 4. Use asynchronous loading; 5. Optimize images. These practices can improve the efficiency, maintainability and user experience of web pages.

Web standards and technologies have evolved from HTML4, CSS2 and simple JavaScript to date and have undergone significant developments. 1) HTML5 introduces APIs such as Canvas and WebStorage, which enhances the complexity and interactivity of web applications. 2) CSS3 adds animation and transition functions to make the page more effective. 3) JavaScript improves development efficiency and code readability through modern syntax of Node.js and ES6, such as arrow functions and classes. These changes have promoted the development of performance optimization and best practices of web applications.

H5 is not just the abbreviation of HTML5, it represents a wider modern web development technology ecosystem: 1. H5 includes HTML5, CSS3, JavaScript and related APIs and technologies; 2. It provides a richer, interactive and smooth user experience, and can run seamlessly on multiple devices; 3. Using the H5 technology stack, you can create responsive web pages and complex interactive functions.

H5 and HTML5 refer to the same thing, namely HTML5. HTML5 is the fifth version of HTML, bringing new features such as semantic tags, multimedia support, canvas and graphics, offline storage and local storage, improving the expressiveness and interactivity of web pages.

H5referstoHTML5,apivotaltechnologyinwebdevelopment.1)HTML5introducesnewelementsandAPIsforrich,dynamicwebapplications.2)Itsupportsmultimediawithoutplugins,enhancinguserexperienceacrossdevices.3)SemanticelementsimprovecontentstructureandSEO.4)H5'srespo

The tools and frameworks that need to be mastered in H5 development include Vue.js, React and Webpack. 1.Vue.js is suitable for building user interfaces and supports component development. 2.React optimizes page rendering through virtual DOM, suitable for complex applications. 3.Webpack is used for module packaging and optimize resource loading.

HTML5hassignificantlytransformedwebdevelopmentbyintroducingsemanticelements,enhancingmultimediasupport,andimprovingperformance.1)ItmadewebsitesmoreaccessibleandSEO-friendlywithsemanticelementslike,,and.2)HTML5introducednativeandtags,eliminatingthenee

H5 improves web page accessibility and SEO effects through semantic elements and ARIA attributes. 1. Use, etc. to organize the content structure and improve SEO. 2. ARIA attributes such as aria-label enhance accessibility, and assistive technology users can use web pages smoothly.


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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6
Visual web development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.