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 string, write a log here, make a distinction
1. String Object
A string i
JavaScript Array-Array method summary (recommended), javascriptarray
The Array type in JavaScript is frequently used. The Array type also provides many methods to meet our needs. Let's summarize the following:
1. method for creati
This article mainly introduces the use cases of JavaScript Array functions unshift, shift, pop, and push. This article first explains how to declare arrays, and then provides some examples for the use of the four functions, for more information, see
How to declare an array
whose element order is reversed.ArrayObj. reverse ()ParametersArrayObj is required. This parameter is an Array object.DescriptionThe reverse method reverses the element positions in an Array object. During execution, this method does not create a new Array object.If the array is not continuous, the reverse method crea
Sparse array and dense array in javascript
When learning about the apis related to the underscore. js array, I encountered sparse array, which I had never touched before.
Here we will learn what sparse arrays and dense arrays are.
What is dense
Document directory
1:
2:
An array object uses a separate variable name to store a series of values.Instance
Create an array
Create an array, assign values to it, and then output these values.
For... in statement
Use the for... in Declaration to cyclically output the elements in the array
In JavaScript, all but 5 of the original data types are objects, including functions.5 Types of raw data:
Number
Boolean
String
Null
Undefined
In this context, let's talk about JavaScript objects.1. Create objectsvar obj = {}; A way of creating an object, called the object Direct amount (object Literal) var obj = new Object (); Create an empty object, as with {}For more knowled
attributes: constructor, length, and prototype.---> Constructor, as its name implies, is a constructor, that is, what the object is composed of. In other words, it is the object type. See the following example.Var arr = new Array (3 );If (arr. constructor = Array){Document. write ("This is an Array ");}If (test. constructor = Boolean){Document. write ("This is a
){Document. write ("This is an Array ");}If (test. constructor = Boolean){Document. write ("This is a Boolean ");}If (test. constructor = Date){Document. write ("This is a Date ");}If (test. constructor = String){Document. write ("This is a String ");}The output above is: This is an Array---> Length, that is, the length of ArrayVar arr = new Array (3 );Document.
Array object (Array object) and javascriptarray in JavaScript
1. method for creating an Array object:
---> Var arr = [1, 2, 3]; // simple definition method
Now you can know
Arr [0] = 1; arr [1] = 2; arr [2] = 3; ---> new Array (); var arr = new
Array.prototypeThe standard method on an object is designed to be reused on other objects-even if it is not an object that inherits from an array. Therefore, passbook some class array object (Array-like Objects) in JavaScript. A typical example is the arguments object of the function, which is described in Item 22. The
This article describes how to add and delete elements to and from a JavaScript Array object. Examples of how to use pop, push, splice, and concat methods are summarized, for more information about how to add and delete elements to and from a JavaScript Array, see the examples in this article. Share it with you for your
Summary of adding and deleting elements to and from Array objects in JavaScript Array, javascriptarray
This example summarizes how to add and delete elements to and from a JavaScript Array object. Share it with you for your reference. The specific analysis is as follows:
Pop
beginning to the end if omitted) returns an array of deleted elements, returning an empty array without deleting var a = [1,2,3,4,5,6,7,8]; A.splice (4); // = = Returns [5,6,7,8];a is [1,2,3,4] (A.splice); // = = Returns [2,3];a is [1,4] A.splice (a); // = = return [4];a Yes [1] The first two parameters specify the array elements that need to be
example
var arr = new Array (3);
if (Arr.constructor==array)
{
document.write ("This was an Array");
}
if (Test.constructor==boolean)
{
document.write ("This is a Boolean");
}
if (test.constructor==date)
{
document.write ("This is a Date");
}
if (test.constructor==string)
{
document.write ("This is a String");
The result of the above output is that
1. sparse arrayIt is easy to create a sparse array with a specified length:Copy codeThe Code is as follows:> Var a = new Array (3 );>[,]> A. length3> A [0]Undefined When you traverse it, you will find that it does not have elements. JavaScript will skip these gaps.Copy codeThe Code is as follows:> A. forEach (function (x, I) {console. log (I + "." + x )});> A. ma
How can I tell if a JavaScript variable is an array or a obiect?
Answer:
1, if you just use typeof to check the variable, whether it is array or object, will return to ' objec '.
One possible answer to this problem is to check that the variable is not object and check that the variable has a number length (the length may also be 0 when it is an empty
instance of the object "inherits" the action given to the object's prototype.For array objects, use the following example to illustrate the purpose of the prototype property.Adds a method to the array object that returns the value of the largest element in the array. To do this, declare a function, add it to array.pro
Next is a "JavaScript array array Basics", which details all the methods of array.
The methods of all arrays are defined on Array.prototype, and the Array.prototype itself is an array.
Array.concat ()
Shallow copies the current array
Article Introduction: the array in JavaScript.
Array is a commonly used type in JavaScript, and arrays in JavaScript are quite different from arrays in other languages. The data types that are stored in an array in
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.