This article introduces common objects in js, including descriptions of JavaScript objects string objects date () array mathematical object function objects. For more information, see
What is an object?
To put it simply, the objects in programming languages are simplified for things in reality. For example, we are an object, but it is difficult for programming languages to fully describe such a complex object. Therefore, we must simplify the process. First, we should simplify people into a combination of attributes and actions, and then only keep the attributes and actions that are meaningful to the program. For example, if we develop a program to count the heights of people in a school, we can omit the human behaviors in this program and only keep the behaviors, only the height attribute is retained. In this way, we get the simplest object.
JavaScript string object
Object Attributes
In fact, we are already using objects in html dom. For example, we know that DOM nodes have some information, such as nodeName and nodeType, which are actually the attributes of node objects. The following uses a string as an example to check the attributes of an object.
String attributes
Var s = "I have a 7 character"; after defining the string s, we have a string object. We can access its length attribute (length ), this attribute does not need to be defined. It is a built-in attribute. The access method is as follows:
S. length click the button below to see the length of the string.
Alert (s. length)
String object method (behavior)
Similarly, an object can have behavior. Taking a String object as an example, we can let the string return letters or texts at a certain position. This is an action. You can use the buttons below to experience the attributes and methods of the string. This article will explain in detail how to use each method.
The Code is as follows: