Object
object sort by value
1 2 3 4 5 6 7
| const obj = { 'us': {'population': 331449281}, 'jp': {'population': 125360000}, 'in': {'population': 1352642280} }
Object.keys(obj).sort((a, b) => obj[a]['population'] - obj[b]['population']).map(item => obj[item])
|
注意
用数字作为对象的key,内部会自动转换为string
Array
concat
concat(value0, value1, ... , valueN)
1 2 3 4 5 6
| const array1 = ['a', 'b', 'c']; const array2 = ['d', 'e', 'f']; const array3 = array1.concat(array2);
console.log(array3); // expected output: Array ["a", "b", "c", "d", "e", "f"]
|
map
map(function callbackFn(element, index, array) { ... }, thisArg)
1 2 3 4 5 6 7
| const array1 = [1, 4, 9, 16];
// pass a function to map const map1 = array1.map(x => x * 2);
console.log(map1); // expected output: Array [2, 8, 18, 32]
|
filter
filter(function callbackFn(element, index, array) { ... }, thisArg)
1 2 3 4 5 6
| const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
const result = words.filter(word => word.length > 6);
console.log(result); // expected output: Array ["exuberant", "destruction", "present"]
|
参考
Standard built-in objects Array
Array.prototype.concat()
Array.prototype.map()
Array.prototype.filter()