Section 8 Arrays and Arrow Functions

array fill

// The fill method of the instance 

let arr = ['com' , 'http' , 'wwww' , '163' ];

let fillResult = arr.fill('replace' , 1 , 3);


console.log(fillResult);

array loop

// Array loop (emphasis) 

let arr2 = ['com' , 'http' , 'wwww' , '163' ];

let arrentries = arr2.entries();

for(let item of arr2){
    console.log(item);
}

for(let [index , val] of arr2.entries()){
  console.log( "Index is: ",index + "----value is: " + val)
}


console.log(arrentries.next().value);//输出[0, "com"]
console.log(arrentries.next().value);//输出[1, "http"]
console.log(arrentries.next().value);//输出[2, "wwww"]
console.log(arrentries.next().value);//输出[3, "163"]

Array lookup includes method:

// includes method 
/* The second parameter of this method indicates the starting position of the search, which is 0 by default.
If the second parameter is negative, it indicates the position of the reciprocal,
If it is larger than the array length at this time (for example, the second parameter is -4, but the array length is 3),
will reset to start at 0. */


console.log(arr2.includes('com' , 0));

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324612028&siteId=291194637