1.
var data = {a: 1 b: 2 3, D: 4 Span style= "color: #000000;" > }; var result = Object.keys (data). Filter ( function (x) { return D ATA[X] > 2; }); Console.log (result); //["C", "D"]
/*
Explanation: Object.keys () outputs an enumerable property name as an array, object.keys (data) returns an array of ["A", "B", "C", "D"]
Filter () arrays that are an iterative method that runs the given function for each item in a group, and returns the number of items that the function returns True. ,
namely: function (item, index, array)
*/
2. Creation of objects to be examined
function obj (name) { if (name) { returnnew obj (name); } } Obj.prototype.name = "name2"; var a = obj ("name1"); var New obj; Console.log (a.name); // "Name1" Console.log (b.name); // "Name2"
3. Fibonacci Sequence
function Getnthfibonacci (count) { if(Count < 2) { return 1; Else { return Arguments.callee (count-1) + Arguments.callee (count-2// Use Arguments.callee to disassociate the function from the name of the functor } } Console.log (Getnthfibonacci (0)); // 1 Console.log (Getnthfibonacci (4)); // 5
Several Ali pen questions