Purpose

For these two array operation interfaces , Because I don't understand , Often misused , Or don't know how to use . This paper attempts to give an easy to understand exposition .

Array

What is an array ?

Array is a basic data structure , It's a way to organize elements in a linear way in memory , Where elements must be of the same type , The index address of each element can be calculated , Indexes are usually numbers , It is used to calculate the offset of storage position between elements .

The structure is as follows :

javascript Array

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array

javascript in Array It's an object , And it's a global object , Used to create the actual array , An array is a kind of linked list like object .

Create array :

var fruits = ["Apple", "Banana"];

console.log(fruits.length);
// 2

utilize index Accessing array elements :

var first = fruits[0];
// Apple var last = fruits[fruits.length - 1];
// Banana

Traversing array elements :

fruits.forEach(function (item, index, array) {
console.log(item, index);
});
// Apple 0
// Banana 1

Add elements after the array :

var newLength = fruits.push("Orange");
// ["Apple", "Banana", "Orange"]

Remove elements from the end of the array :

var last = fruits.pop(); // remove Orange (from the end)
// ["Apple", "Banana"];

Remove elements from the array head :

var first = fruits.shift(); // remove Apple from the front
// ["Banana"];

Add elements to the head of the array :

var newLength = fruits.unshift("Strawberry") // add to the front
// ["Strawberry", "Banana"];

Find the index number of the element :

fruits.push("Mango");
// ["Strawberry", "Banana", "Mango"] var pos = fruits.indexOf("Banana");
// 1

Use index numbers to delete elements :

var removedItem = fruits.splice(pos, 1); // this is how to remove an item
// ["Strawberry", "Mango"]

Copy an array :

var shallowCopy = fruits.slice(); // this is how to make a copy
// ["Strawberry", "Mango"]

Syntax for creating arrays :

Syntax

[element0, element1, ..., elementN]
new Array(element0, element1[, ...[, elementN]])
new Array(arrayLength)
elementN

A JavaScript array is initialized with the given elements, except in the case where a single argument is passed to the Array constructor and that argument is a number. (See below.) Note that this special case only applies to JavaScript arrays created with the Array constructor, not array literals created with the bracket syntax.

arrayLength

If the only argument passed to the Array constructor is an integer between 0 and 2 32-1 (inclusive), this returns a new JavaScript array with length set to that number. If the argument is any other number, a RangeError exception is thrown.

Array.prototype.slice

slice English translation :

http://www.iciba.com/slice/

The original meaning is A piece of bread Cut it off thin slice .

N-COUNT ( Cut from food ) slice , thin slice A slice of bread, meat, fruit, or other food is a thin piece that has been cut from a larger piece. 

  • Try to eat at least four slices of bread a day.

    Try to eat at least 4 Slice bread .

  • ...water flavored with a slice of lemon.

    With a slice of lemon flavored water

aaarticlea/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMCAgMCAgMDAwMEAwMEBQgFBQQEBQoHBwYIDAoMDAsKCwsNDhIQDQ4RDgsLEBYQERMUFRUVDA8XGBYUGBIUFRT/2wBDAQMEBAUEBQkFBQkUDQsNFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBT/wAARCACYAOQDASIAAhEBAxEB/8QAHgAAAQQDAQEBAAAAAAAAAAAABgAEBQcBAgMICQr/xAA8EAABAwMCBAMFBgUEAwEBAAABAgMEAAURBiEHEjFBEyJRFDJhcYEjQpGh4fAIFSRS0TNyscEWNGJDov/EABsBAAIDAQEBAAAAAAAAAAAAAAQFAQIDAAYH/8QANBEAAQMCAwUGBgICAwAAAAAAAQACAwQREiExQVFhcfATMoGRobEFFCLB0eEjQjPxFWKC/9oADAMBAAIRAxEAPwD6GW2ySbo8lICmG84Lik4IqZl3i16RHsyCuXcFj/12/M4f92PdHzrwPrP+KzjDxInJXaLPe7JascyWbFBewodMrfxnOc9CBVncPOMJtbMZm7lMGa4kGRIuLgSpa+6lGvNTV4iyib4n8J5HQmQXkPh+1fk6Xqi7yHJaJbNnKk8gS2OdSU9skjGap7jA5eG7QsTrDf8AWrbgU297C402tkcvQjAJBBI2G2QanF8d7LIkmMm5W24jOP6SalQUOm3x+lVFrXS9k1VqOTe4uttTWtxxZKY4kIkRmyeqW84KE7dAaXwVTsziNjmdUa6naNW2OgVcsT9IaXeR4rGutGJZACC7CLwRjsVqSoHAqWkfxGakiQQnQ/FXTuqWEnCLXqNkW6QPXz7JP4ipV6xcQrYSLNxSj74AZukd5LZT6EhS+3w3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+tY5f3mtsbD/FLH7xVSuXMp3+nrS5d/1rYjf6elIjf9KrdWste361norPb50sbfpWSP3ipvddZd0qykdfxpVhA8g/xSrl1l+emWp1Di23UlDiCUqSrqCDgim7i8JGaVKs2q7l1gsB5QzVu8FJDtk4gWOWxzA+0IaWE9VJVtj8TSpVoFmvpLprTikOJKk4dJHNmrh0/YvZo6RgBVKlQNL/JI57tUbUnAxrG6KdEIgYzXKRbvERggEUqVNuCWcUKXLhv7VcTIhqS0Xj9qkgYx6j40Z2eyNWmAzFaHlbGOY7E/E0qVZBoByWhcSFKpZ+FbhJA/WlSq6qF0DfTrWfDPb0pUqopWfDVWC2cHNKlXKQseET+dL2c0qVQpWpYVml4BpUq5csezmtSwc+lKlUFSseAoDrWPBV60qVQuWPAUe/akWFA9aVKq7VYLXwlYrCmyD8aVKrKV2SghI+XrSpUqlQv/2Q==" width="357" height="238">

The extended meaning is In the whole Part of the .

N-COUNT part ; Share You can use slice to refer to a part of a situation or activity. 

  • Fiction takes up a large slice of the publishing market.

    Novels occupy a large share of the publishing market .

  • ...a car that represents a slice of motoring history.

    A car that represents a period of automotive history

Combined with the definition of array , This interface is from   Array Cut it off Part of the , Or become a piece of , Maybe the length of the piece is a little big, it becomes a section .

For example, from this array

slice Cut out part of :

MDN Definition

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice

The slice() method returns a shallow copy of a portion of an array into a new array object. 【 Be careful : It's about shallow copy 】

Syntax

arr.slice([begin[, end]])

Parameters

begin

Zero-based index at which to begin extraction.

As a negative index, begin indicates an offset from the end of the sequence. slice(-2) extracts the last two elements in the sequence.

If begin is omitted, slice begins from index 0.

end

Zero-based index at which to end extraction. slice extracts up to but not including end.

slice(1,4) extracts the second element up to the fourth element (elements indexed 1, 2, and 3).

As a negative index, end indicates an offset from the end of the sequence. slice(2,-1) extracts the third element through the second-to-last element in the sequence.

If end is omitted, slice extracts to the end of the sequence ( arr.length) .

explain :

1、 Shallow copy

2、 slice() Without the participation , Then copy the entire array

3、 slice(begin), Only start to participate , namely end Omit , said from begin To arr.length All the elements have achieved .

4、 slice(begin, end) Get subscript as [begin, end-1] The elements of .

5、 begin perhaps end negative , It means counting from the back end of the array .

Example :

// Our good friend the citrus from fruits example
var fruits = ['Banana', 'Orange', 'Lemon', 'Apple', 'Mango'];
var citrus = fruits.slice(1, 3); // citrus contains ['Orange','Lemon']

Array.prototype.splice

splice:

http://www.iciba.com/splice/

VERB Splice ( Rope ); Bonding ( film 、 Tape, etc ) If you splice two pieces of rope, film, or tape together, you join them neatly at the ends so that they make one continuous piece. 

  • He taught me to edit and splice film...

    He taught me how to edit and glue film .

  • The film will be spliced with footage of Cypress Hill to be filmed in America.

    This film is going to be glued to the music clips of the Cypress Mountain band to be shot in the United States .

Splice ( Rope ); Bonding ( film 、 Tape, etc )

take Two paragraphs The film Or rope , Using cement perhaps Splice The way , Connect them , The connection is called The cement 、 The splice ,  That is to say

splice

factitive verb , Namely   Splice 、 cemented ( Connecting two identical strips ).

But search splice picture , There will be a lot of pictures related to a movie ( chinese Crossbreeding between humans and animals The English name is splice):

This story , Two scientists , Against scientific morality , Using human genes and mammalian genes , Do hybridization experiments , Produce a new species , This species is The hybrid (splice), The hybridization is a sequence of genes Splicing , And then the result of hybridization , It's not a human being , Animals are not animals .

Imagine that genes are a long chain , In the gene chain Genome alignment To determine the The characteristics of life , It's up to him to decide a person's life and death .

splice In the movie , The meaning of gene splicing is , Guess the job should be like this , Put the human gene into a strip , Dig out a section (slice), Add a little bit of mammal gene , It's a complementary action , It's splicing splice.

MDN Definition

The splice() method changes the content of an array by removing existing elements and/or adding new elements.

Be careful splice function , Change the contents of an existing array , Its functions include Remove elements and Additive elements .

Syntax

array.splice(start, deleteCount[, item1[, item2[, ...]]])
Parameters
start

Index at which to start changing the array. If greater than the length of the array, actual starting index will be set to the length of the array. If negative, will begin that many elements from the end.

deleteCount

An integer indicating the number of old array elements to remove. If deleteCount is 0, no elements are removed. In this case, you should specify at least one new element. If deleteCount is greater than the number of elements left in the array starting at start, then all of the elements through the end of the array will be deleted.

itemN

The element to add to the array. If you don't specify any elements, splice() will only remove elements from the array.
Returns

An array containing the deleted elements. If only one element is removed, an array of one element is returned. If no elements are removed, an empty array is returned.

explain :

1、 splice Interface Change the contents of an existing array .

2、 splice You can delete elements and Additive elements .  <<---- Function derives from splice The movie .

Delete and add It just reflects the elements of splicing , Delete - Destroyed the existing array , The damage needs to be repaired ,

The result of the patch is to splice new array segments ,splice Splice new array segments , Merge into an existing array .

These two steps , How similar The standard steps of gene splicing in the movie human animal hybridization ( Dig out the bad parts of the human genome , There's no good gene for animals in this position ), doubt js The definition of this interface is , It's receiving splice The inspiration of this movie . Otherwise, according to the English definition , splice Only the meaning of splicing , There is no meaning to dig out , We should not implement the function of digging out in this interface .

3、splice(begin, count), From begin Location start delete count Elements .

begin A negative value means counting forward from the end of the array .

If count Larger than array from begin The number of elements in position calculation , By the end, all elements will be deleted .

4、splice(begin, 0, itema), It means that begin Add... After position itema Elements .

5、splice(begin, 1, itema, itemb), Full function usage , stay begin Position starts to delete an element , Then replace the element where it was deleted   itema and itemb.

6、 splice return Delete the element's Array .

Example :

var myFish = ['angel', 'clown', 'mandarin', 'surgeon'];

// removes 0 elements from index 2, and inserts 'drum'
var removed = myFish.splice(2, 0, 'drum');
// myFish is ['angel', 'clown', 'drum', 'mandarin', 'surgeon']
// removed is [], no elements removed // removes 1 element from index 3
removed = myFish.splice(3, 1);
// myFish is ['angel', 'clown', 'drum', 'surgeon']
// removed is ['mandarin'] // removes 1 element from index 2, and inserts 'trumpet'
removed = myFish.splice(2, 1, 'trumpet');
// myFish is ['angel', 'clown', 'trumpet', 'surgeon']
// removed is ['drum'] // removes 2 elements from index 0, and inserts 'parrot', 'anemone' and 'blue'
removed = myFish.splice(0, 2, 'parrot', 'anemone', 'blue');
// myFish is ['parrot', 'anemone', 'blue', 'trumpet', 'surgeon']
// removed is ['angel', 'clown'] // removes 2 elements from index 3
removed = myFish.splice(3, Number.MAX_VALUE);
// myFish is ['parrot', 'anemone', 'blue']
// removed is ['trumpet', 'surgeon']

Array.prototype.slice && Array.prototype.splice More related articles on usage

  1. slice,Array.prototype.slice,Array.protyotype.slice.call

    slice characteristic : Create a new array based on one or more items in the current array .[ The original array will not be modified ] Return results : Return to a beginning to end ( Not including the end ) A portion of the selected array is shallowly copied to a new array object . grammar : arr.slice() ...

  2. Array.prototype.slice Usage details

    slice The method is defined in js Methods in array prototypes , Used to intercept some elements of an array , The specific use is as follows : arrayExample.slice(start, end); start Is the starting element position ,end Is the cut-off element position , Such as : ...

  3. Detailed explanation go Linguistic array and slice 【 Two 】

    It was explained in the last article ,array and slice Some basic usage of , Use array and slice What to pay attention to , especially slice There are many things to pay attention to . At the end of the last article, we talked about creating new slice Use a third index to limit sl ...

  4. javascript in Array.prototype.slice Usage of .

    First of all to see www.w3school.cn Explanation above :http://www.w3school.com.cn/jsref/jsref_slice_array.asp Definition and Usage slice() The method can be used from the existing ...

  5. Array.prototype.slice() Usage of

    We know ,Array.prototype.slice.call(arguments) Can have length The object of the property is converted to an array , except IE Set of nodes under ( because ie Under the dom The object is to com In the form of objects ,js ...

  6. 【javascript skill 】Array.prototype.slice The magic effect of

    Array.prototype.slice The magic effect of Come to the point , About Array Of slice Please refer to here for the usage of  http://www.w3school.com.cn/js/jsref_slice_arra ...

  7. ( turn )Array.prototype.slice.call Self solution

    This sentence is used in many frameworks or libraries , Most of them are through Array.prototype.slice.call(arguments,0) hold arguments This pseudo array is converted to a real array . But why can it be done , But one ...

  8. Detailed explanation Array.prototype.slice.call(arguments)

    First ,slice There are two uses , One is String.slice, One is Array.slice, The first one returned is the string , The second is an array Here we look at the second method 1. stay JS in Array Is a class slice yes ...

  9. Array.prototype.slice.call(arguments) Class array into a real array

    Array.prototype.slice.call(arguments)   We know ,Array.prototype.slice.call(arguments) Can have length Property of the object into a number ...

Random recommendation

  1. About mysql Of access denied Error resolution

    mysql -u root -p Press enter , After entering the password, prompt access denied......ues password YES/NO Error of ? First step : At this point you need to enter /etc/mysql Under the table of contents , then s ...

  2. Orthomcl Detailed use of

    After referring to many articles and combining with the actual operation, I feel . Reference resources :http://www.plob.org/2013/09/18/6174.html Reference resources :http://www.plob.org/2012/06/12/22 ...

  3. stay Linux The amazing exclamation point under the command line (!)

    '!' The sign is in Linux It can not only be used as a negative sign , It can also be used to retrieve commands from historical command records or execute previously run commands without modification . All of the following commands are already in Bash Shell It's been tested exactly in . Even though I haven't tried , But most of them can't ...

  4. primary !! java When printing an object directly , It's not called directly toString Method , It's about judging whether it's null, Not null Will call toString Method

    I watched a lot on the Internet java When printing an object directly , Directly call the toString Method . however : Object obj=null; System.out.println(obj);// No report error System.o ...

  5. CentOS+Nginx+PHP+MySQL Detailed configuration ( The illustration )

    Original address : http://www.jb51.net/article/26597.htm CentOS+Nginx+PHP+MySQL Detailed configuration ( With illustrations ), Friends in need can refer to .   One . install MySQL ...

  6. BZOJ 1305: [CQOI2009]dance dance ( Maximum flow )

    Yunshen code is very short ...0 ms Yes ... Look at the code , Probably greedy ... orz I don't know It's OK to make such a mess of data ... ←_← The network flow of this question can still be written ... Since it's limited, we can only communicate with k A person I don't like da ...

  7. 2018-2019-2 20175213 Experiment 1 《Java Familiarity with development environment 》 Experimental report

    The first part is the experimental requirements :1 establish “ My student number exp1” The catalog of 2 stay “ My student number exp1” Create under directory src,bin Such as catalog 3 javac,java Execution in “ My student number exp1” Catalog 4 Submit Linux or Window or ...

  8. Luogu p1586 The solution of the square theorem

    subject The essence of this problem is the knapsack problem in dynamic programming . Why do you think of backpacks . Because often the number of schemes is either permutation or recursion or dp, Of course, there are other possibilities . We can take the cost of a number as the square of the number , Value is a number of solutions . Because of this ...

  9. The first 15 Chapter Bit operation (fields)

    /*----------------------------------- fields.c -- Define and use fields -----------------------------------*/ #inc ...

  10. django Study ~ Fourth articles

    django Forms    1  Let's continue today django Form for         First of all http Methods , This is the most basic        GET Method GET Generally used for obtaining / Inquire about Resource information , With ? Division URL And transmit data ...