Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand the histochemistry in javascript

Shulou Source: shulou.com Published: 2022-06-02 17:10:57 09月14日 Update

This article introduces the relevant knowledge of "how to understand the histochemistry in javascript". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

General methods of numerical histochemistry

1. The first and most common method, [] .slice.call method

Function toArray (obj) {

1.

Return [] .slice.call (obj)

two。

/ / Array.prototype.slice.call ()

3.

}

Ps: this method is actually a reference method, the comment part is fully written, and what is returned is an array object.

two。 The second method draws lessons from the makeArray method in jq.

Function makeArray (obj) {

1.

Var target = []

two。

If (obj! = null) {

3.

Var I = obj.length

4.

If (I = null | | typeof obj = = 'string' | | typeof obj = =' function' | |

5. Obj.setInterval) {/ /

If it is a string, a function win object, pay this element to the first element that creates the array and return it

Target [0] = obj

1.

} else {/ / if not the above elements, assign each obj to every index of target through a loop

two。

While (I) {

3.

Target [--I] = obj [I]

4.

}

5.

}

6.

}

7.

Return target

}

3. The third method

Function $arr (ele) {

1.

If (! ele) {

two。

Return []

3.

}

4.

If (ele.toArray) {

5.

Return ele.toArray ()

6.

}

7.

Var length = ele.length | | 0, results = new Array (length)

8.

While (length--) {

9.

Results [length] = ele [length]

10.

}

11.

Return results

twelve。

}

This is the end of the content of "how to understand the histochemistry in javascript". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Methods arrays elements contents objects that is more knowledge practicality learning next writing functions dilemmas characters strings actual common situations articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno NVidia MySQL Huawei Apple