The examples in this article summarize common methods for array (array) objects and string objects in JavaScript. Share to everyone for your reference, specific as follows:
Summary: The author often confuse the method of array and the method of
Push Method
Adds a new element to an array and returns the new length value of the array.
Arrayobj.push ([Item1 [item2 [...] [Itemn]]])
Parameters
Arrayobj required option. An Array object.
Item, Item2,... itemn option. The new element of
1, slice method (Array)
Returns a section of an array.
Arrayobj.slice (start, [end])
Parameters
Arrayobj
Required option. An Array object.
Start
Required option. The starting element of the part specified in Arrayobj is the zero-based subscript.
Push methodAdds a new element to an array and returns the new length value of the array.
Arrayobj.push ([Item1 [item2 [...] [Itemn]]])
Parameters
Arrayobj required option. An Array object.
Item, Item2,... itemn option. The new element of the
Problems encountered
We have a problem today, delete one of the specified elements in the array, and return the new array.
The JS array I defined is like this:
var sexlist=new array[3];
sexlist[0]= "1";
sexlist[1]= "2";
Sexlist[2]= "";
Javascript| Object | advanced
First, write the constructorYou can use the new operator to combine predefined constructors such as Object (), Date (), and function () to create and initialize an object. The powerful feature of object-oriented
Sometimes there are repeating elements in the array, and we don't need to do that for the arrays.There are many ways to go heavy, and here are several ways to easily understand them.1, first to the simplest methodUse the new data structure set
Original: JavaScript array attributesAn array is a linearly allocated memory that computes offsets and accesses the elements in an integer. An array is a data structure with excellent performance. 1. Array literalsArray literals provide a very
Add or remove an element at the end of an array: Push () and pop ()
Push (): Appends one or more elements to the tail of the array and returns the length of the arrayPop (): Deletes an element at the end of the array and returns the deleted
The Splice method in 1:jsSplice (Index,len,[item]) Comment: The method changes the original array.The splice has 3 parameters, which can also be used to replace/delete/Add one or more values within an arrayIndex: Array start subscript len:
1 Object Typevar person = new Object (); Person.name = "Summer"; and var person = {name: ' Summer '}; is equivalent.2 Array Type(1) var colors = new Array (); and var colors = Array (); and var colors = []; is equivalent.(2) The Length property in
1. means of definition;var arr = []; Array literalvar arr = new Array (); Array constructorsArray all methods are derived from Array.prototype2. Reading and writing of arrays;Arr[num]//Can not overflow read results undefinedArr[num] = xxx; Can
Determine if an object is an array: instanceof, Array.isarray ()You can use the instanceof operator for a Web page or for a global scope.if instanceof Array) { // Determine if value is an array }instanceof Operator It assumes that there is only
Yesterday to soak up the majority of days of the book Hall, a breath of reading the "JavaScript Grammar essence" of the books, the overall book is still written well, no wonder so many recommendations. "The essence of JavaScript grammar" is mainly
This article translates the JavaScript Tutorial playlist of up master Kudvenkat on YouTubeSOURCE Address here:https://www.youtube.com/watch?v=PMsVM7rjupU&list=PL6n9fhu94yhUA99nOsJkKXBqokT3MBK0bThere are many ways in JavaScript that can be used on a
Array definition:var arr = [12,5,8,9];var arr = new Array (12,5,8,9);The length property of the array:
1. length allows you to get the lengths of the array and the length of the array.
2. Unlike other languages, the length of the JS
First, find the position of the element item in the given array arr, otherwise return-1Find robust code for the position of an element two, calculate the sum of the given array elements (the element is number type)There are many ways to do this,
ArrayArrayProvides a function to store a set of elements sequentially, and can be read and written by index. JavaScript Array can contain arbitrary data types, and each element is accessed through an index.To get Array the length, directly access
Array de-weight methodmethod One: Apply the Splice () method and the double-layer for loop (sort of a similar selection)function Norepeat (arr) {for (var i = 0;i j--;}}} return arr; }Note: If you do not add j--, you will be removed, skipping a
arrays, strings, and numbers are the most basic components of a program, and for programmers, understanding them is just the basic operation, and today we're talking about arraysUnlike other strongly typed languages, arrays can hold any type of
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.