Contents:
-
The concat() method is used to join two or more arrays.
-
This method does not change the existing arrays, but returns a new array, containing the values of the joined arrays.
Ex:
var hege = ["Cecilie", "Lone"];
var stale = ["Emil", "Tobias", "Linus"];
var kai = ["Robin"];
var children = hege.concat(stale, kai);
//children === [Cecilie, Lone, Emil, Tobias, Linus, Robin]-
The filter() method creates an array filled with all array elements that pass a test (provided as a function).
-
syntax: array.filter(function(currentValue, index, arr), thisValue)
var words = ['spray', 'limit', 'elite', 'exuberant', 'destruction']
const result = words.filter(word => word.length > 6);
//output: ['exuberant', 'destruction', 'present']var fruits = ['apple', 'banana', 'grapes', 'mango', 'orange'];
function filterItems(arr, query) {
return arr.filter(element => {
return element.toLowerCase().indexOf(query.toLowerCase())
});
}
console.log(filterItems(fruits, 'ap')); // ['apple', 'grapes']
console.log(filterItems(fruits, 'an')); // ['banana', 'mango', 'orange']