Page 120 - JavaScript
P. 120
[1, 1, 1].every(function(item, i, list) { return item === list[0]; }); // true
6
[1, 1, 1].every((item, i, list) => item === list[0]); // true
The following code snippets test for property equality
let data = [
{ name: "alice", id: 111 },
{ name: "alice", id: 222 }
];
data.every(function(item, i, list) { return item === list[0]; }); // false
data.every(function(item, i, list) { return item.name === list[0].name; }); // true
6
data.every((item, i, list) => item.name === list[0].name); // true
Copy part of an Array
The slice() method returns a copy of a portion of an array.
It takes two parameters, arr.slice([begin[, end]]) :
begin
Zero-based index which is the beginning of extraction.
end
Zero-based index which is the end of extraction, slicing up to this index but it's not included.
If the end is a negative number,end = arr.length + end.
Example 1
// Let's say we have this Array of Alphabets
var arr = ["a", "b", "c", "d"...];
// I want an Array of the first two Alphabets
var newArr = arr.slice(0, 2); // newArr === ["a", "b"]
Example 2
// Let's say we have this Array of Numbers
https://riptutorial.com/ 77

