Browser kernel, arrays, and strings

Composition of browser

  1. shell
  2. Kernel part
    • Rendering engine (syntax rules and rendering)
    • js engine

Javascript consists of three parts: ECMAScript, DOM and BOM

Compiling language: C, C + +,

  • Advantages: fast
  • Insufficient: poor portability (not cross platform)

Interpretation language: Javascript

  • Advantages: cross platform, single thread
  • Insufficient: slightly slow
Mainstream browser kernel

IE trident

Chrome blink/webkit

firefox Gecko

Opera presto

safari webkit

data type

Original value:


Reference value:

array, Object, function ········ date, Regexp

Any type + string is equal to string

a + +: execute before operation

++a: Operation before execution

&&Operator stops when it encounters false

||Operators stop when they encounter the truth

typeof: number,string,boolean,object,function,undefined

  • Number: convert type data to number

  • parselnt (string, radius): convert data to integer · - 123abc=123

  • parseFloat (string): convert data to floating point

  • String: convert data into a string

  • Boolean: convert data type to Boolean value (true, false)

    typeof (a): undefined / / no variable declared

    arguments: argument array (argument list)

    Return: terminate the function and return the value

    typeof(null): object

    Most of the number symbols are converted to number type -- NAN is the one that cannot be converted



Class array

  1. If the attribute is an index (numeric) attribute, it must have a length attribute, and it is best to add push

  2. Once you add a splice method to an object, the object looks like an array

    var obj={
        "0" :"a",
  • Principle of class array push
Array.prototype.psh=function (target){

time stamp

Get the total number of milliseconds of Date, not the number of milliseconds of the current time, but the number of milliseconds since January 1, 1970

  1. Through valueof() getTime()
var date=new Date();
  1. Simple writing method (the most commonly used writing method)
var date=+new Date();
  1. H5 total number of milliseconds added

Array string jion() and split();

var str='12345';
str.split('')//['1', '2', '3', '4', '5']
var arr=[1,2,3,4,5]
//Using the jion() method is a string type

Detect whether it is an array

  1. instanceof operator, which can be used to detect whether it is an array
var arr[];
console.log(arr instanceof Array);//true
  1. Array. Isarray (parameter); H5 newly added ie9up

Original array change

  1. push() adds one or more array elements to the end of our array;
  2. unshift() adds one or more array elements at the beginning of our array;
  3. pop() deletes the last element of the array; Only one element is deleted at a time, so no parameters are required. The deleted element is returned;
  4. shift() can delete the first element of the array;

Returns the index number of an array element

Indexof (array element) is used to return the so number of the array element and search from the front

It only returns the first index number that meets the condition,

If it cannot find an element in the array, the returned time is - 1;

LastIndexOf (array element) find from the back

Convert array to string

  1. toString() converts our array to a string
var arr=[1,2,3];
  1. Join (separator)
var arr1=['green','blue','red'];

The string object returns the position indexOf according to the character ('string to find ', [starting position] optional)

Returns characters based on position

1.charAt(index) returns characters according to the position;

var str='andy';
//Traverse all characters
for(var i=0;i<srt.length;i++){
  1. charCodeAt(index) returns the character ASCII value of the corresponding index number. Purpose: to judge which key the user pressed

  2. str[index];

Operation method of string

  1. concat('string ',' string 2 '...),, connection string
var str='andy';
  1. sbustr('Start position of interception ',' several characters of interception ');
var str1 ='The spring breeze of reform is blowing all over the ground';
console.log(str1.substr(2,2));//Spring breeze / / the first 2 is the 2 of the index number, and the second 2 is the number of characters
  1. The replacement character replace('replaced character ',' replaced character ') will only replace the first character;
var str='andyandy';

//There is a string 'abcoefoxyozzopp' that requires the replacement of o with*

  //There is a string 'abcoefoxyozzopp' that requires the replacement of o with*
      var str='abcoefoxyozzopp';
      str=  str.replace('o','*');
  1. Convert character to array split('separator ')
var str2='red','green','blue';
  • toUpperCase() / / convert to uppercase
  • toLowerCase() / / convert to lowercase

Keywords: Javascript Front-end html5

Added by ajanoult on Sat, 19 Feb 2022 18:46:17 +0200