- arr.slice( begin[, end] )
var students = [
{id: 1, score: 80},
{id: 2, score: 50},
{id: 3, score: 70}
];
var newStudents = students.slice(0, 2);
/*
[
{id: 1, score: 80},
{id: 2, score: 50}
];
*/ - arr.concat( value1, ..., valueN )
var students1 = [
{id: 1, score: 80},
{id: 2, score: 50},
{id: 3, score: 70}
];
var students2 = [
{id: 4, score: 90},
{id: 5, score: 60}
];
var students3 = [
{id: 6, score: 40},
{id: 7, score: 30}
];
var newStudents = students1.concat(students2, students3);
/*
[
{id: 1, score: 80},
{id: 2, score: 50},
{id: 3, score: 70},
{id: 4, score: 90},
{id: 5, score: 60},
{id: 6, score: 40},
{id: 7, score: 30}
];
*/ - arr.join( [separator] )
var emails = ["wq@163.com","gp@163.com","xl@163.com"];
emails.join(";"); // => "wq@163.com;gp@163.com;xl@163.com" - arr.map( callback[, thisArg] )
var scores = [60,70,80,90];
var addScore = function (item, index, array) {
return item + 5;
}
var newScores = scores.map(addScore); // => [65,75,85,95] - arr.reduce(callback[, initialValue])
var students = [
{id: 1, score: 80},
{id: 2, score: 50},
{id: 3, score: 70}
];
var sum = function(previousResult, item, index, array) {
return preiousResult + item.score;
};
students.reduce(sum, 0); // => 200
网友评论