- The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place.
array.splice(start[, deleteCount[, item1[, item2[, ...]]]]
- The slice() method returns a shallow copy of a portion of an array into a new array object selected from begin to end (end not included). The original array will not be modified.
arr.slice([begin[, end]
- The find() method returns the value of the first element in the array that satisfies the provided testing function. Otherwise undefined is returned.
- The find method executes the callback function once for each index of the array until it finds one where callback returns a true value.
arr.find(callback(element[, index[, array]])[, thisArg])
- The findIndex() method returns the index of the first element in the array that satisfies the provided testing function. Otherwise, it returns -1, indicating no element passed the test.
arr.findIndex(callback(element[, index[, array]])[, thisArg])
- Find the middle point
- Circular list?
- Step back from tail
The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place.
array.splice(start[, deleteCount[, item1[, item2[, ...]]]]
会修改原数组!
var months = ['Jan', 'March', 'April', 'June'];
months.splice(1, 0, 'Feb');
// inserts at 1st index position
console.log(months);
// expected output: Array ['Jan', 'Feb', 'March', 'April', 'June']
months.splice(4, 1, 'May');
// replaces 1 element at 4th index
console.log(months);
// expected output: Array ['Jan', 'Feb', 'March', 'April', 'May']
The slice() method returns a shallow copy of a portion of an array into a new array object selected from begin to end (end not included). The original array will not be modified.
arr.slice([begin[, end]
不会修改原数组!
_
var animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];
console.log(animals.slice(2));
// expected output: Array ["camel", "duck", "elephant"]
console.log(animals.slice(2, 4));
// expected output: Array ["camel", "duck"]
console.log(animals.slice(1, 5));
// expected output: Array ["bison", "camel", "duck", "elephant"]
The find() method returns the value of the first element in the array that satisfies the provided testing function. Otherwise undefined is returned.
The find method executes the callback function once for each index of the array until it finds one where callback returns a true value.
arr.find(callback(element[, index[, array]])[, thisArg])
var array1 = [5, 12, 8, 130, 44];
var found = array1.find(function(element) {
return element > 10;
});
console.log(found);
// expected output: 12
The findIndex() method returns the index of the first element in the array that satisfies the provided testing function. Otherwise, it returns -1, indicating no element passed the test.
arr.findIndex(callback(element[, index[, array]])[, thisArg])
var array1 = [5, 12, 8, 130, 44];
function isLargeNumber(element) {
return element > 13;
}
console.log(array1.findIndex(isLargeNumber));
// expected output: 3
Find the middle point
Circular list?
if (slow === fast) return true;