Undersacore, to determine whether the data exists

 1.has_.has(object, key) 

Does the object contain the given key? Equivalent to object.hasOwnProperty(key) , but uses a safe reference to the hasOwnProperty function to prevent accidental overwriting . 

 

 
 
_.has({a: 1, b: 2, c: 3}, "b");
=> true
 
 

 

Note: has is to determine whether the key used for the object exists

 

2.indexOf_.indexOf(array, value, [isSorted]) 

Returns the index value of value in the array , or -1 if value does not exist in the array . Use the native indexOf function unless it fails. If you are working with a large array, and you know the array is already sorted, passing true to isSorted will make it faster to use binary search .., or, pass a number as the third argument to search for the first index in the array at a given index a matching value.    

 

_.indexOf([1, 2, 3], 2);
=> 1

 

 

index position

 

It can also be used to: determine whether there is an element a in the array :

 

Var list = [1,12,4,5,1,2,]

 

If(list.indexOf('10')==-1){ // The judgment statement in if is: 10 is not in the list array

 

Console.log(‘ture’)

 

}

 

The result is: true;

 

3. contains alias : include_.contains(list, value)   

Returns true if the list contains the specified value (note: use === to detect). If list is an array, indexOf is used internally 

 

_.contains([1, 2, 3], 3);
=> true

 

 

 

Contains, also judges whether there is an element in the array;

 

4. find alias : detect_.find(list, predicate, [context])   

Search item by item in the list , return the value of the first element tested by the truth value of the predicate iterator function, or return it if no value is passed to the test iterator . If a matching element is found, the function will return immediately without traversing the entire list .undefined

 
var search=[1,2,4,5,6,3,8];
_.find(array,function(num){return num%2==0}
=>2
Traverse the array and only return the first data for which the condition is true.
However, filter will return all the data that meets the conditions, reject is the opposite of filter.
 
 

 

5 .where _.where (list, properties)  iterates over each value in the list and returns an array that containsall the key-value pairs for the properties listed in properties.

_.where(listOfPlays, {author: "Shakespeare", year: 1611});
=> [{title: "Cymbeline", author: "Shakespeare", year: 1611},
    {title: "The Tempest", author: "Shakespeare", year: 1611}]

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326941421&siteId=291194637