js third day summary

--------------------------------New knowledge today---------------- ---------------------

One: Object Class (category)

Object-oriented: Object-oriented is a programming idea, one is the concept of class, and the other is the concept of object

Class: abstract; object: instantiated, concrete; for example, this computer in the computer class is a concrete instantiation of a certain class

(The first letter of the identifier of the class is generally capitalized) (The built-in class of the system and the custom class are all instantiated as objects)

Review data types: basic data types (number string boolean undefined null)

Reference data type: object function arr

Data classification in js: any data in js can find the corresponding category (the first letter is usually uppercase)

Each class in js corresponds to many objects

classes and objects?

A class refers to a certain class, abstract, and an object is instantiated and concrete (an object is a specific class of a certain class)

Object: It is the specificity of a certain class. An object is also called an instance. An object is an unordered collection of attributes (a collection is a container)

In addition to using built-in objects in js, you can create objects yourself

There are two ways to create objects:

The literal way (that is, the way of key-value pairs):

For example:

was however1={

name: "Hahaha",

age:4,

eat:function(){

      consle.log("I will eat")

};

console.log(dog1.name);

console.log(dog1.age);

console.log(dog1.eat());

}

Create objects through the new class new is an operator.

var a=new Number (1) judge whether a belongs to the object of number

(1)console.log(typeof  a)object

(2)console.log(a instanceof number) true

Get the properties in the object, object name. property name

The second way to create an object:

var obj=new Object()

obg.name="XXX"

console.log(obj.name)//xxx

Get the method in the object, object name. method name

obj.eat=function(){

console.log("eat ...")

}

obg.eat();

Second, the commonly used classes in js  

Understand the built-in classes of js?

Date class : Provides date-related operations

year getFullYear, month getMonth, day getDate hour getHours, minute getHours, second getSecond

Math class: (no need for new) Provide math-related operations random floor ceil round

three arrays

1) An array is a collection of ordered data, two ways to create an array?

(1) By means of literal quantity

var arr1=[10, 20, 20, 31, "Zhang", "", "zhihuimin"]

(2) Instantiation, that is, a new array

var arr2=new Array(“a”,“b”,“c”);

2) How to judge whether a data is an array?

console.log(arr instanceof Array);true

console.log(Array.isArray(arr);true

console.log(arr typeof Array); object

3) Pay attention to details:

When giving Array a data, if it is a numeric type, it means returning an empty array of the length

The index starts from 0 and increases sequentially, which can be discontinuous

Any type of data can be placed in the array

Arrays are dynamic and can grow or shrink according to the length of the array.

4) Operation array

CRUD:

var arr =new Array(a,b,c,d)

access:

console.log(arr[0])//a

Add to:

arr【4】=e

console.log(arr)//[a,b,c,d,e]

Modify element:

arr【2】=123;

console.log(arr)//[a,123,c,d,e]

The property of the array: length

The length of the array can be obtained by the array name.length

console.log (arr.length) to get the length of the array

four strings

1) Two ways to create a string

by literal means

var s1 = "Hello";

console.log(typeof s1)//string

via new a class

var s2=new String("zhang")

console.log(typeof s2)//object

console.log(s2 instanceof string)//true

Five common methods in arrays and strings

array

通过数组方法操作数组?
    push  在末尾追加元素  返回新数组长度  改变原数组
   unshift  在开头追加元素   返回新数组长度  改变原数组
    pop  删除末尾元素  返回被删除的元素  改变原数组 
   shift  删除开头元素   返回被删除的元素  改变原数组
   reverse  将数组反转  返回反转后的数组  改变原数组 
   sort 把数组中的元素进行排序  返回排序后的数组   改变了原数组  如果需要对数组中的数字进行排序,需要传递一个比较函数,比较函数有两个参数,如果返回第1个参数-第2个参数,是升序, 如果返回第2个参数-第1个参数,是降序
    
   slice 用来截取数组的 返回一个新数组 不改变原数组
   toString 把数组转成字符串 返回一个字符串  不改变原数组
   join  把数组转成字符串   返回字符串  不改变原数组
   concat  多个数组连接成一个数组   返回连接后的新数组  不改变原数组

String method:

concat returns a string starting from the specified position to the specified number of characters (without changing the original string)

Find: (do not change the original string)

charAt : returns the specified character of the value     

charcodeAt: returns the ascii code of the character specified by the value 

indexof: Returns the index (from left to right) of the first occurrence of the character with its specified value

lastindexof: Returns the index of the last occurrence of the character with its specified value (from right to left)

search: returns the index corresponding to the character, if not found, returns -1

intercept

substr: returns the characters from the specified position to the specified number of characters

substring: returns a subset from the start index to the end index (end is not intercepted) (not possible) (start is negative and turns to zero)

slice: returns a subset from the start index to the end index (end is not intercepted) (can be used in an array) (take negative to length+start, length+end processing)

case conversion

toLowercase converts the string to lowercase and returns

toUppercase converts the string to uppercase and returns

replace

replace returns the new string after replacement

turn array

split: use the specified delimiter to split the string object into a string array (without a delimiter, it will be converted to an element in an array by default)

Guess you like

Origin blog.csdn.net/zwy1231/article/details/103342603